我正在尝试在树枝中创建一个多级菜单
你能根据我的代码给我一个例子吗?
第一个菜单工作正常,我听说不得不使用宏,但我不知道它是如何工作的
外观:
.twig:
<ul class="header_desktop_categories_ul">
{% if cat_pai_desktops %}
{% for cat_pai_desktop in cat_pai_desktops %}
<li>
<a href='{{constant('BASE')}}/produtos/{{cat_pai_desktop.cat_name}}' title='{{cat_pai_desktop.cat_title}}'>{{cat_pai_desktop.cat_title}}</a>
{% if cat_filha_desktops %}
<div>
<div>
{% for cat_filha_desktop in cat_filha_desktops %}
<ul>
<li><a href="{{constant('BASE')}}/produtos/{{cat_filha_desktop.cat_name}}" title="{{cat_filha_desktop.cat_title}}">{{cat_filha_desktop.cat_title}}</a></li>
{% if cat_subfilha_desktops %}
{% for cat_subfilha_desktop in cat_subfilha_desktops %}
<li><a href="{{constant('BASE')}}/produtos/{{cat_subfilha_desktop.cat_name}}" title="{{cat_subfilha_desktop.cat_title}}">{{cat_subfilha_desktop.cat_title}}</a></li>
{% endfor %}
{% endif %}
</ul>
{% endfor %}
</div>
</div>
{% endif %}
</li>
{% endfor %}
{% endif %}
</ul>
php:
$Read->FullRead("SELECT cat_id, cat_title, cat_name FROM " . DB_PDT_CATS . " WHERE cat_parent IS NULL ORDER BY cat_title ASC");
if ($Read->getResult()):
$cat_pai_desktop = $Read->getResult();
foreach ($Read->getResult() as $SES):
$Read->FullRead("SELECT cat_id, cat_title, cat_name FROM " . DB_PDT_CATS . " WHERE cat_parent = :cat ORDER BY cat_title ASC", "cat={$SES['cat_id']}");
if ($Read->getResult()):
$cat_filha_desktop = $Read->getResult();
foreach ($Read->getResult() as $CAT):
$Read->setPlaces("cat={$CAT['cat_id']}");
if ($Read->getResult()):
$cat_subfilha_desktop = $Read->getResult();
endif;
endforeach;
endif;
endforeach;
endif;
和
print $twig->render('header.twig', array(
'cat_pai_desktops' => $cat_pai_desktop,
'cat_filha_desktops' => $cat_filha_desktop,
'cat_subfilha_desktops' => $cat_subfilha_desktop
));
但这不能正常运作