LoginSignup
3
4

More than 5 years have passed since last update.

twig で再帰処理をしたい場合は、 macro を使う

        {% macro recursiveCategories(Category) %}
            {% if Category.hasChildNodes() %}
                <ul>
                    {% for child in Category.childNodes() %}
                        <li>{{ child.name }}</li>
                        {{ _self.recursiveCategories(child) }}
                    {% endfor %}
                </ul>
            {% endif %}
        {% endmacro %}
        {% if Category.hasChildNodes() %}
        <ul>
            {% for ChildCategory in Category.childNodes() %}         
                <li>{{ ChildCategory.name }}</li>
                {{ _self.recursiveCategories(ChildCategory) }}         
            {% endfor %}
        </ul>
        {% endif %}

参考

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4