包含root的路径

时间:2015-04-01 13:05:52

标签: path smarty

我的结构有点像这样:

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

我想在tpl2.tpl中加入tpl1.tpl,我该如何避免这样的怪物:{include file="../../../../../dir1/dir2/dir3/tpl.tpl"}

1 个答案:

答案 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"}

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