[英]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: 在使用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}
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? 如果我想更改此行以在HTML中添加两个META标签,那么定义
header.html
模板要查找的数组的正确语法是什么?
Caveat: I'm unfamiliar with PHP, so I apologize if this is an obvious newbie question. 警告:我不熟悉PHP,因此,如果这是一个显而易见的新手问题,我深表歉意。 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.
另外,从对源代码的一些挖掘和下面的注释中,我相信该站点将Smarty用于模板引擎,尽管我不能确定它不是派生版本。
Try something like: in PHP: 尝试类似的方法:在PHP中:
$smarty->assign("myArray",array("some_key" => "some_value","key2" => "value2"));
in SMARTY: 在SMARTY中:
{include file="header.html" title="your title" myParam=$myArray}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.