簡體   English   中英

將數組參數傳遞給smarty PHP模板包括

[英]passing array parameters to smarty PHP template include

在使用smarty模板引擎(或至少smarty的近親)的PHP站點上,我正在調用包含此代碼摘錄以及此處為清楚起見而省略的其他HTML的模板包含文件(“ header.html”):

<title>{$title|escape:"html"}</title>
{if isset($META) && $META}
    {foreach from=$META item=m}
        <meta name="{$m[0]}" content="{$m[1]}">
    {/foreach}
{/if}

我當前在父頁面模板中有以下行:

{include file="header.html" title="My WebSite Title Goes here"}

如果我想更改此行以在HTML中添加兩個META標簽,那么定義header.html模板要查找的數組的正確語法是什么?

警告:我不熟悉PHP,因此,如果這是一個顯而易見的新手問題,我深表歉意。 另外,從對源代碼的一些挖掘和下面的注釋中,我相信該站點將Smarty用於模板引擎,盡管我不能確定它不是派生版本。

嘗試類似的方法:在PHP中:

$smarty->assign("myArray",array("some_key" => "some_value","key2" => "value2"));

在SMARTY中:

{include file="header.html" title="your title" myParam=$myArray}

暫無
暫無

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

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