简体   繁体   中英

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}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM