Prestashop 显示产品类别和子类别

Prestashop display product categories and subcategories

在产品页面上,我想显示分配给产品的所有类别和子类别。是这样的: -第 1 类 --子1 --子2 -第 2 类 --子3 --Sub4

我当前的代码是:

{foreach from=$product_categories item=product_category}
                    {if $product_category.id_category != 2}
                        <li >
                            <a href="{$link->getCategoryLink($product_category.id_category, $product_category.link_rewrite)}"
                            title="{$product_category.name}">{$product_category.name}</a>
                        </li>   
                    {/if}
                {/foreach}

但是它在没有类别树的情况下在每一行中打印所有类别。

您需要使用嵌套函数生成一棵树,然后才能在页面上显示它,就像 Prestashop 在 Blockcategories 模块中所做的那样。

为什么不使用这个模块 (Blockcategories) 作为模式?