Smarty有两条不同的路径?

时间:2014-05-18 05:04:05

标签: php smarty

我在php项目中使用smarty

|->app
    |view
        |path_returned_by_handler.tpl
|->lib
    |abstract
        |controller.php
    |view
        |path_to_be_used_by_controller.tpl

有一些处理程序将路径返回到某个sub_template但是在显示中我想使用/lib/view/path_to_be_used_by_controller.tpl 在这个文件中,我将使用这样的处理程序返回的路径 {include file =" $ path_returned_by_handler"标题=" sub_temp"}

我该怎么做? 1)一个解决方案是我使用绝对路径,并且根本不使用setTemplateDir或设置为顶级父目录,并使用相对路径。 任何更好的解决方案?

1 个答案:

答案 0 :(得分:0)

如果你想使用相对路径,你需要在include

的开头使用./

结构:

| index.tpl
  |test
      test.tpl
      test3.tpl
      |test2
           test2.tpl

在index.tpl

{include file="test/test.tpl"}

test.tpl

I'm test<br />

{include "./test3.tpl"}

{include "./test2/test2.tpl"}

test2.tpl

I'm test 2<br />

test3.tpl

I'm test 3<br />

显示index.tpl时的结果是:

I'm test
I'm test 3
I'm test 2

因此模板中的相对路径可以正常工作。它在最新的Smarty 3.1.18中进行了测试