将数组参数传递给 smarty PHP 模板包括

发布于 2024-09-12 09:13:43 字数 641 浏览 1 评论 0原文

在使用 smarty 模板引擎(或至少是 smarty 的近亲)的 PHP 站点上,我调用一个模板包含文件(“header.html”),其中包含此代码摘录,以及为了清楚起见而省略的其他 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当前父页面模板中有此行:

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

如果我想更改此行以将两个 META 标记添加到我的 HTML 中,定义 header.html 模板正在查找的数组的正确语法是什么为了?

警告:我不熟悉 PHP,所以如果这是一个明显的新手问题,我深表歉意。另外,通过对源代码的一些挖掘和下面的评论,我相信该网站正在使用 smarty 作为模板引擎,尽管我不能确定它不是分叉版本。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葮薆情 2024-09-19 09:13:43

尝试类似的方法:
在 PHP 中:

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

在 SMARTY 中:

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

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}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文