Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

smarty, include tpl file

Tags:

php

smarty

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

like image 562
lolalola Avatar asked Nov 27 '10 12:11

lolalola


3 Answers

Change

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

to

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

This will at least determine the current location you're at.

like image 170
foxns7 Avatar answered Oct 09 '22 03:10

foxns7


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 .

like image 29
Kos Avatar answered Oct 09 '22 02:10

Kos


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.

like image 24
luison Avatar answered Oct 09 '22 02:10

luison