2015-04-01 72 views
0

路徑我有一個結構,有點像這樣:包括從根

src 
---stuff1 
------stuff2 
---------stuff3 
------------tpl1.tpl 
---dir1 
------dir2 
---------dir3 
------------tpl2.tpl 

我想包括在tpl1.tpltpl2.tpl,我怎樣才能避免怪物像這樣:{include file="../../../../../dir1/dir2/dir3/tpl.tpl"}

+0

我會定義一個根路徑變量,並使用絕對路徑,而不是相對路徑 – slaver113 2015-04-01 13:27:52

+0

你介意給我一個例子嗎?我似乎無法找到任何答案。 – AlexG 2015-04-01 13:44:21

回答

1

php文件:

<?php 
$root = "/path/to/the/root/of/my/site/or/templates" 
$smarty->assign('root',$root); 

模板文件:

{include file="`$root`/dir1/dir2/myfile.tpl"} 

{include file="$root/dir1/dir2/myfile.tpl"} 

{include file="$root|cat:"/dir1/dir2/myfile.tpl"} 

http://www.smarty.net/docs/en/language.syntax.quotes.tpl