包括从根

包括从根

问题描述:

路径我有一个结构,有点像这样:包括从根

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

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