1

I am working with Python and Flask at the moment, and I wanting to do a check in my template for if a value is contained in an array that is passed to template the code that build the array looks like this,

statuses = {}
statuses['personal_status'] = ['Pending', 'Cancelled']
statuses['planner_status'] = ['Pending', 'RP_Approved', 'RP_Declined', 'Cancelled', 'Approved']
statuses['approver_status'] = ['Approved', 'Mgr_Declined']

In my template I am wanting search statuses.personal_status to see if a value is present in the array and if so show some other DOM elements, is this possible?

Udders
  • 6,914
  • 24
  • 102
  • 194
  • in jinja (i assume you use it) you can just execute normal python code, which mean you can just use an if statement with ` 'value_to_check' in statuses.personal_status` – René Jahn Dec 30 '16 at 12:55
  • Possible duplicate of [How do you index on a jinja template?](http://stackoverflow.com/questions/20233721/how-do-you-index-on-a-jinja-template) – dahrens Dec 30 '16 at 12:56

1 Answers1

4

You might consider the following code in your template:

<div>
{% if 'specific_status' in statuses.personal_status %}
    yay
{% endif %}
</div>
René Jahn
  • 1,155
  • 1
  • 10
  • 27