lolalola
lolalola

Reputation: 3823

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 resource: "modules/news.tpl"

File exist and is in modules/news.tpl directory.

Thanks

Upvotes: 5

Views: 21997

Answers (4)

foxns7
foxns7

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

luison
luison

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

Chandresh M
Chandresh M

Reputation: 3828

you have to include this file in php (action) files and then it will works in tpl as well.

Thanks.

Upvotes: 0

Kos
Kos

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

Related Questions