Reputation: 3823
how include file with smarty? i use this function: {include file="modules/news.tpl"}
but show error:
Warning: Smarty error: unable to read resource: "modules/news.tpl"
File exist and is in modules/news.tpl directory.
Thanks
Upvotes: 5
Views: 21997
Reputation: 91
Change
{include file="modules/news.tpl"}
to
{include file="./modules/news.tpl"}
This will at least determine the current location you're at.
Upvotes: 9
Reputation: 2110
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.
Upvotes: 2
Reputation: 3828
you have to include this file in php (action) files and then it will works in tpl as well.
Thanks.
Upvotes: 0
Reputation: 72319
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 .
Upvotes: 5