0

I have a list of categories from DB as following and it works fine + sorted by ID.

{% for category in menu_categories|sort(attribute="id"):  %}    
<div>
    {{ category.name }}
</div>
{% endfor %}

I just need one exception if category='Pizza' exist to list it first.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Fi3n1k
  • 863
  • 3
  • 12
  • 20

1 Answers1

1

Unless I misunderstood you, this should do it:

{% for category in menu_categories|sort(attribute="id"): %}
    {% if category.name == 'Pizza': %}
        <div> {{ category.name }} </div>
    {% endif %}
{% endfor %}
{% for category in menu_categories|sort(attribute="id"): %}
    {% if category.name != 'Pizza': %}
        <div> {{ category.name }} </div>
    {% endif %}
{% endfor %}
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
  • Thank you but I need entire list except only if category PIZZA exist to be listed first. – Fi3n1k Oct 15 '12 at 09:38
  • That's what this does; it will list the Pizza category first, then all those that aren't Pizza. – Burhan Khalid Oct 15 '12 at 09:39
  • @BurhanKhalid please look at this question for a minute [http://stackoverflow.com/questions/12890935/how-to-translate-an-app-template] if YOU can help me please post your answer there Thanks – Inforian Oct 15 '12 at 11:46
  • I think using the sort filter to list the Pizza category first could be faster. Although that's just speculating. – Markus Unterwaditzer Jan 24 '13 at 11:48