EgzEst EgzEst - 5 months ago 99x
CSS Question

python ternary in jinja2 gives TemplateSyntaxError: tag name expected

I have a table and I want to change background color of tr if value of person.storyPublished is true otherwise do nothing.

My code looks like this:

{% for person in people %}
<tr class="row-person {% '.row-story-published' if person.storyPublished else ' ' %}" >
{{ }}

I get this error:

TemplateSyntaxError: tag name expected

and the CSS part is here:

background-color: #b3ffb3;

why is this happening? What i miss that I don't notice? Any help :)


You used "{% %}" which wants to get a tag like if, endif etc. If you just want to execute a piece of python code, like your ternary expression, you should use double braces like so

{{ 'row-story-published' if  person.storyPublished  else ' ' }}