Smarty, include tpl file

How to include a file with smarty? I use this function: {include file = "modules / news.tpl"}

but show the error:

Warning: Smarty error: Unable to read resource: "modules / news.tpl"

The file exists and is located in the modules / news.tpl directory.

thanks

+4
source share
4 answers

Edit

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

to

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

This will at least determine your current location.

+7
source

While I'm not 100% sure, I believe that Smarty allows your inclusion by looking at the template_dir configuration.

See the document: http://www.smarty.net/docs/en/variable.template.dir.tpl and http://www.smarty.net/docs/en/language.function.include.tpl .

+5
source

Unfortunately, Smarty requires absolute paths. Usually we set the enocroot $ docroot variable in PHP and parse it into patterns so we can use it:

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

I understand that this is one smarty re-request to be able to include templates in the same way as the current one.

+2
source

you must include this file in php (action) files, and then it will work in tpl too.

Thanks.

0
source

All Articles