繁体   English   中英

聪明,包括tpl文件

[英]smarty, include tpl file

怎么用smarty包含文件? 我使用这个函数:{include file =“modules / news.tpl”}

但显示错误:

警告:Smarty错误:无法读取资源:“modules / news.tpl”

文件存在并位于modules / news.tpl目录中。

谢谢

更改

{include file="modules/news.tpl"}

{include file="./modules/news.tpl"}

这将至少确定您当前所处的位置。

虽然我不是100%肯定在这里,但我相信Smarty通过查看template_dir配置变量来解析你的包含。

请参阅doc: http//www.smarty.net/docs/en/variable.template.dir.tplhttp://www.smarty.net/docs/en/language.function.include.tpl

不幸的是,Smarty需要绝对路径。 我们通常在PHP中设置$ docroot环境变量并将其解析为模板,以便我们可以使用它:

{include file =“$ docroot / modules / news.tpl”}

我理解这是一个重复的请求,以便能够在与当前路径相同的路径中包含模板。

你必须将这个文件包含在php(动作)文件中,然后它也可以在tpl中使用。

谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM