Skip to content

Instantly share code, notes, and snippets.

@marekkalnik
Created May 13, 2013 12:18
Show Gist options
  • Save marekkalnik/5567913 to your computer and use it in GitHub Desktop.
Save marekkalnik/5567913 to your computer and use it in GitHub Desktop.
utilisation d'un macro pour une fonction récursive dans Twig
{% import _self as brandOrder %}
{% extends 'TheodoDemoBundle::base.html.twig' %}
{% macro brandOrder(brand) %}
<li class="nav level{{ brand.treeLevel }} more">
<div id="brand{{ brand.id }}"><span>{{ brand.title }}</span></div>
{% if brand.children|length > 0 %}
{% import _self as brandHelper %}
<ul>
{% for brandChildren in brand.childrenOrdered %}
{{ brandHelper.brandOrder(brandChildren) }}
{% endfor %}
</ul>
{% endif %}
</li>
{% endmacro %}
{% block content %}
<div class="span6 right">
<h3>Les marques</h3>
<ul id="brand-list" class="brand nav nav-pills nav-stacked">
{% for brand in brands %}
{{ brandOrder.brandOrder(brand) }}
{% endfor %}
</ul>
</div>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment