prestashop url to category



[PRESTASHOP 1.7]我想在ps_categorytree之外显示类别。

模块代码如下:

$allCategories = Category::getNestedCategories(null, $this->context->language->id);
$this->context->smarty->assign( 'allCategories' , $allCategories );
return $this->fetch('module:'.$this->name.'/views/templates/widget/block.tpl');

。tpl文件:

{foreach from=$allCategories item=mainCategory}
<a href="{$mainCategory.link}">{$mainCategory.name}</a>
{foreach from=$mainCategory.children item=subCategory}
<a href="{$subCategory.link}">{$subCategory.name}</a>
{/foreach}

错误:Notice: Undefined index: link

如何分配链接?

因为您将Category作为数组,而不是对象。

尝试使用mainCategory['link']代替mainCategory。链接,等等

我误解了你的问题,对不起!试试这个。

{foreach $allCategories as $mainCategory}
{$link->getCategoryLink($mainCategory.id_category, $mainCategory.link_rewrite)|escape:'html':'UTF-8'}
{/foreach}

如果smarty文件中没有$link变量,你应该赋值给它

'link' => $this->context->link,

最新更新