0

I try to generate a var name from another var value. To be more specific I'm in a loop and I try to display all parameters of an object, based on the loop incrementation. Example: I have a list of objects categories. I have an object diplayer which contain parameters cat_1, cat_2, cat_3 etc I try to do something like this

{% for category in categories %}
   {{ displayer.cat_(category.id) }}
{% endfor %}

Of course my probleme is (category_id) I really don't know how to get value of category.id to use it in the param name of the object.

For information I can not use a dictionary in place of the object displayer.

An idea?

Thanks a lot

Tartempion34
  • 492
  • 6
  • 23

1 Answers1

0

This kind of logic has to be done in Python beforehand. See this similar issue.

If you really really want to do the logic in the template (not advised), you can use custom template tags.

Cyrlop
  • 1,894
  • 1
  • 17
  • 31
  • Thanks I used custom template tags and it works fine. But I'm not sure we can say I do logic in the template it's juste that the vars in the dict are named weirdly, I just read a dict in the template – Tartempion34 Sep 08 '18 at 11:59