为什么在模板文件变量的属性是通过点(.)但是添加的变量是通过箭头(->)获得的。在mainmenu.tpl中,我有:
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中:
{$menu.label}
{$product->name}
{$product.name} //not render如何用点来获取每个属性?
发布于 2022-06-26 07:43:22
(.)访问器在引用关联数组的属性时使用,并在这种类型中传递大多数预存储库对象。因此,应该将对象转换为数组:
$this->smarty->assign('product', (array)$product);https://stackoverflow.com/questions/72759499
复制相似问题