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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With