簡體   English   中英

Smarty中的兩條不同路徑?

[英]Two different paths in 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_us_ed_by_controller.tpl,在此文件中,我將使用處理程序返回的路徑,例如{include file =“ $ path_returned_by_handler” title = “ sub_temp”}

我該怎么做呢? 1)一種解決方案是我使用絕對路徑,而不是完全使用setTemplateDir或設置為頂級父目錄,而從那里使用相對路徑。 有更好的解決方案嗎?

如果要使用相對路徑,則需要在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中進行了測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM