对于聪明的小新手但是我觉得我已经做得很好了,所以我有一个foreach使我的菜单工作得很好但生成的列表项对于菜单来说太长了所以想要将菜单分成每10个单独的列表例如但似乎无法破解它?有人有什么想法吗?
我到目前为止的代码:
{foreach from=$item1.$childs item="item2" name="item2"}
{if $smarty.foreach.item2.index % 10 == 0}
<ul class="menu-col">
{/if}
{assign var="item_url2" value=$item2|fn_form_dropdown_object_link:$block.type}
<li class="ty-menu__submenu-item{if $item2.active || $item2|fn_check_is_active_menu_item:$block.type} ty-menu__submenu-item-active{/if}{if $item2.class} {$item2.class}{/if}">
<a class="ty-menu__submenu-link" {if $item_url2} href="{$item_url2}"{/if}>{$item2.$name}</a>
</li>
{if $smarty.foreach.item2.index % 10 == 0}
</ul>
{/if}
{/foreach}
然而它似乎产生了这样的结果:
<ul class="menu-col">
<li class="ty-menu__submenu-item ty-menu__submenu-item-active">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/vip-air-mesh/">VIP (Air Mesh)</a>
</li>
</ul>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/vip-bonded-pu-leather/">VIP (Bonded PU Leather)</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/vip-vintage-denim/">VIP (Vintage Denim)</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/zen-lounger/">Zen Lounger</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/acoustic-sofa/">Acoustic Sofa</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/avatar-lounger/">Avatar Lounger</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/butterfly-sofa/">Butterfly Sofa</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/the-boss/">The Boss</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/wing-ottoman/">Wing Ottoman</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/conversion-lounger/">Conversion Lounger</a>
</li>
<ul class="menu-col">
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/evolution-sofa/">Evolution Sofa</a>
</li>
</ul>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/fiorenze-leather-sofa/">Fiorenze Leather Sofa</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/ottomans/">Ottomans</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/roma-sofa/">Roma Sofa</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/snugg-sofa/">SNUGG Sofa</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/space-pod/">Space Pod</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/studio-lounger/">Studio Lounger</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/tech-pillow-rest-pad/">Tech Pillow Rest Pad</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/tivoli-lounger/">Tivoli Lounger</a>
</li>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/twin-couch-sofa/">Twin Couch Sofa</a>
</li>
<ul class="menu-col">
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/versa-table/">Versa Table</a>
</li>
</ul>
<li class="ty-menu__submenu-item">
<a class="ty-menu__submenu-link" href="/interior-bean-bags/cloudchair/">Cloudchair (Air Mesh)</a>
</li>
但我需要它像
<ul>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
</ul>
<ul>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
<li>blah</li>
</ul>
<ul>
<li>blah</li>
<li>blah</li>
</ul>
答案 0 :(得分:0)
尝试在foreach外面移动打开和关闭主ul,然后添加条件以重新启动它,如果当前迭代是10的倍数并且它不是最后一个值(所以你不要结束如果数组恰好有10个值,则为空ul;
<ul class="menu-col">
{foreach from=$item1.$childs item="item2" name="item2"}
{if $smarty.foreach.item2.iteration % 10 == 0 && !$smarty.foreach.item2.last}
</ul>
<ul class="menu-col">
{/if}
{assign var="item_url2" value=$item2|fn_form_dropdown_object_link:$block.type}
<li class="ty-menu__submenu-item{if $item2.active || $item2|fn_check_is_active_menu_item:$block.type} ty-menu__submenu-item-active{/if}{if $item2.class} {$item2.class}{/if}">
<a class="ty-menu__submenu-link" {if $item_url2} href="{$item_url2}"{/if}>{$item2.$name}</a>
</li>
{/foreach}
</ul>