1

I have this:

{% for row in data: %}
    <td
            {{'value={{row['value']}}' if 'showit' in map and header in map['showit'] and 'value' in row}}
    > ... </td>
{% endfor %}

But obviously that's not working. Trying to add an HTML attribute to the cell using a secondary column in the row dict. Any thoughts?

1
  • 1
    expression should be in {% ... %}. you can check the expression and then use {{row['value']}}. Commented Dec 14, 2014 at 19:32

1 Answer 1

1

Assuming your trouble is with the syntax getting the row['value'], concatenate the strings rather than trying to nest the {{ }}s:

{{ 'value=' + row['value'] if True }}

Replace the True with your condition of course. If you need to quote the param:

{{ 'value="' + row['value'] + '"' if True }}

As @Reza-S4 suggested you can also put the conditional outside the print statement to be a little clearer:

{% if 'showit' in map and header in map['showit'] and 'value' in row: %}
  value="{{ row['value'] }}"
{% endif %}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.