duanlu4371 2018-11-22 14:02
浏览 87
已采纳

PHP for循环在Twig中

I have a small problem with looping in Twig. How to loop the whole sub-nav? Currently it makes sub-nav in sub-nav nested.

{% if categories %}
    {% for category in categories %}
    <ul class="sub-nav">
      <li>
        <a href="{{ category.href }}" class="cat-name">{{ category.name }}</a>

        <ul class="sub-sub-nav list-inline">
          {% if category.children %}
          <li class="list-inline">
            <a class="sub-cat-name" href="">{% for children in category.children|batch(category.children|length / category.column|round(1, 'ceil')) %}</a>
            <ul class="sub-cat-menu">
              {% for child in children %}
              <li><a href="{{ child.href }}">{{ child.name }}</a></li>
              {% endfor %}
            </ul>
            {% endfor %}</li>
          <a href="{{ category.href }}" class="see-all">{{ text_all }} {{ category.name }}</a>
        </ul>
        {% endif %}
      </li>
      {% else %}
      <li><a href="{{ category.href }}">{{ category.name }}</a></li>
    {% endfor %}
    </ul>
  • 写回答

3条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 结构体数组文件读取问题
      • ¥15 写c++代码,第7题说一下使用的计算方法
      • ¥15 postman接口自动化测试报告实践总结
      • ¥15 有关c++的问题,利用相关知识
      • ¥15 求香农编码和解码的matlab代码
      • ¥20 ROS中的TEB局部规划问题
      • ¥20 关于#matlab#的问题:要求测出上面图片中所有同心圆的半径
      • ¥20 epanet软件运行问题
      • ¥15 Python 文件读取
      • ¥60 dpabi进行Alff计算时脑池有干扰信号