首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Prestashop 1.7智能引擎将变量从控制器传递到.tpl文件

Prestashop 1.7智能引擎将变量从控制器传递到.tpl文件
EN

Stack Overflow用户
提问于 2022-06-26 06:54:09
回答 1查看 350关注 0票数 1

为什么在模板文件变量的属性是通过点(.)但是添加的变量是通过箭头(->)获得的。在mainmenu.tpl中,我有:

代码语言:javascript
复制
public function renderWidget($hookName, array $configuration)
{

    $this->smarty->assign([
        'menu' => $this->getWidgetVariables($hookName, $configuration),
    ]);
    
    // assign new variable
    $id = 661;
    $id_lang = $this->context->language->id;
    $product = new Product((int) $id, false, (int) $id_lang);
    $this->smarty->assign('product', $product);

    return $this->fetch('module:ps_mainmenu/ps_mainmenu.tpl');
}

在ps_mainmenu.tpl中:

代码语言:javascript
复制
    {$menu.label}
    {$product->name}
    {$product.name} //not render

如何用点来获取每个属性?

EN

回答 1

Stack Overflow用户

发布于 2022-06-26 07:43:22

(.)访问器在引用关联数组的属性时使用,并在这种类型中传递大多数预存储库对象。因此,应该将对象转换为数组:

代码语言:javascript
复制
$this->smarty->assign('product', (array)$product);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72759499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档