Prestashop 1.7:在 tpl 文件中显示类别列表

问题描述 投票:0回答:1

我想显示404页面的tpl文件中的类别列表。

可以在此数组中访问要显示的类别:

    $categories Array (5)
  0 => Array (4)
    id_category => "720"
    name => "brakes"
    link_rewrite => "brakes"
    id_shop => "7"
  1 => Array (4)
    id_category => "721"
    name => "tyres"
    link_rewrite => "tyres"
    id_shop => "7"
  2 => Array (4)
    id_category => "722"
    name => "bumpers"
    link_rewrite => "bumpers"
    id_shop => "7"
  3 => Array (4)
    id_category => "723"
    name => "interiors"
    link_rewrite => "interiors"
    id_shop => "7"
  4 => Array (4)
    id_category => "724"
    name => "accessories"
    link_rewrite => "accessories"
    id_shop => "7"

在 tpl 中我添加了以下代码:

<ul>
    {foreach from='$categories' item='category'}
        <li>{$category.name}</li>
    {/foreach}
</ul>

我不明白为什么不显示类别名称(我假设 foreach 循环应该显示类别名称)。

谢谢您的帮助。

arrays foreach prestashop smarty prestashop-1.7
1个回答
0
投票

您必须删除

$categories
周围的引号,否则您将在字符串而不是数组中搜索。

<ul>
    {foreach from=$categories item='category'}
        <li>{$category.name}</li>
    {/foreach}
</ul>
© www.soinside.com 2019 - 2024. All rights reserved.