Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

702
Vistas
Conditional element classes with jinja, I want a div to get a class if a list item contains a certain item

I'm making a a little job board and I have little cards for each job. These cards are dynamically created from a list sent from my python script to the html using flask/jinja

jobs = [{'title':'fix car', 'description':'my car broke down', 'price':100}]

HTML example

{% for item in jobs %}

<p> {{ item['title'] }} {{ item['description'] }} {{ item['price'] }} </p>

{% endfor %}

Screenshot of job tasks

What I would like is to be able to make selected cards stand out, or featured. So in my Python script where the jobs come from I've added a binary option. 1 = featured, 0 = normal

So In my html it would look something like this:

{% for item in jobs %}

<p class='featured if item['featured']'> {{ item['title'] }} {{ item['description'] }} {{ item['price'] }}

{% endfor %}

so it would get a new CSS class if its featured key is set to 1.

CSS example

.featured {
    background-color: blue;
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can use an inline conditional for a shorter result:

<p class='{{"featured" if item["featured"] else "normal"}}'> {{ item['title'] }} {{ item['description'] }} {{ item['price'] }}</p>

However, if you do not want to include a class for non-featured cards, a generic if-else statement can be used:

{%if item["featured"]%}
  <p class='featured'> {{ item['title'] }} {{ item['description'] }} {{ item['price'] }}</p>
{%else%}
  <p> {{ item['title'] }} {{ item['description'] }} {{ item['price'] }}</p>
{%endif%}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda