默认情况下,Tera会对文件名称结尾是.html, .html和.xml的文件中的内容进行转义处理如果想了解Tera处理的方式可以看这里OWASP.,我来为大家科普一下关于rust语言文档?下面希望有你要的答案,我们一起来看看吧!

rust语言文档(Rust模板引擎Tera中文英文对照官方文档-自动转义和实例)

rust语言文档

自动转义(Auto-escaping)

默认情况下,Tera会对文件名称结尾是.html, .html和.xml的文件中的内容进行转义处理。如果想了解Tera处理的方式可以看这里OWASP.

By default, Tera will auto-escape all content in files ending with ".html", ".htm" and ".xml".Escaping follows the recommendations from OWASP.

如果想自己定义那些文件需要转义可以使用autoescape_on方法

You can override that or completely disable auto-escaping by calling the autoescape_on method:

//只转义文件名结尾是.php.html的文件 // escape only files ending with `.php.html` tera.autoescape_on(vec![".php.html"]); //不转义任何文件 // disable autoescaping completely tera.autoescape_on(vec![]);

高级一点的用法(Advanced usage)实例扩展(extending another instance)

如果你使用的框架或者库已经使用了tera,它定义了自己模板、过滤器、全局函数或者测试器,我们能不能直接复用人家定义好的配置呢?这就要用到extend方法了,使用它可以用一个先前已经存在的tera实例去扩展我们新创建的实例。

If you are using a framework or a library using Tera, chances are they provide their own Tera instance with somebuilt-in templates, filters, global functions or testers. Tera offers a extend method that will extend your owninstance with everything mentioned before:

let mut tera = Tera::new(&tpl_glob).chain_err(|| "Error parsing templates")?; //这里的ZOLA_TERA是外部库已经定义好的Tera实例 // ZOLA_TERA is an instance present in a library tera.extend(&ZOLA_TERA)?;

如果在自己定义的Tera实例和扩展用的Tera实例存在同名的模板文件或过滤器什么的会发生啥子?如果有同名的会使用自己定义的。

If anything - templates, filters, etc - with the same name exists in both instances, Tera will only keep yours.

,