我的结构有点像这样:
src
---stuff1
------stuff2
---------stuff3
------------tpl1.tpl
---dir1
------dir2
---------dir3
------------tpl2.tpl
我想在tpl2.tpl
中加入tpl1.tpl
,我该如何避免这样的怪物:{include file="../../../../../dir1/dir2/dir3/tpl.tpl"}
?
答案 0 :(得分: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"}