开发者

passing array parameters to smarty PHP template include

On a PHP site using the smarty template engine (or at least a close relative of smarty), I am calling a template include file ("header.html") which contains this code excerpt, along with other HTML omitted here for clarity:

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

I currently have this line in开发者_开发问答 the parent page template:

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

If I want to change this line to add two META tags into my HTML, what is the right syntax to define the array which the header.html template is looking for?

Caveat: I'm unfamiliar with PHP, so I apologize if this is an obvious newbie question. Also, from some digging in the source code and from the comments below, I believe the site is using smarty for a template engine, although I can't be sure it's not a forked version.


Try something like: in PHP:

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

in SMARTY:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜