smarty, include tpl file
how include file with smarty? i use this function: {include file="modules/news.tpl"}
but show error:
Warning: Smarty error: unable to read re开发者_StackOverflow社区source: "modules/news.tpl"
File exist and is in modules/news.tpl directory.
Thanks
Change
{include file="modules/news.tpl"}
to
{include file="./modules/news.tpl"}
This will at least determine the current location you're at.
While I'm not 100% sure here, I believe that Smarty resolves your includes by looking in the template_dir
config variable.
See the doc: http://www.smarty.net/docs/en/variable.template.dir.tpl and http://www.smarty.net/docs/en/language.function.include.tpl .
Smarty requires absolute paths unfortunately. We normally set a $docroot enviroiment variable in PHP and parse it to the templates so we can use it:
{include file="$docroot/modules/news.tpl"}
I understand this is a one repeated request to smarty to be able to include templates on the same path as the current one.
you have to include this file in php (action) files and then it will works in tpl as well.
Thanks.
精彩评论