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

371
Vistas
Check if key exists in array in nunjucks template (Node JS)

I am creating an application in Node Js using Nunjucks template engine and I have to apply permissions on pages to show add, edit and delete links.

For this I have implemented an array of permissions like below :

var user_params = ['add_user', 'edit_user', 'delete_user'];

Now I want to check on pages that add_user exists in user_params array or not just like we do in php

in_array('add_user', user_params)

But I am being able to perform this task in nunjucks. So can anyone help me out ?

Thanks in advance

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You should be able to do this:

{% if 'add_user' in user_params %}
   do stuff in html
{% endif %}

For indexOf, I'm not sure that works but even if it did, if zero evaluates to false that's not good either if you're testing the first row. would also need to check > -1

over 4 years ago · Santiago Trujillo Denunciar

0

The only way I found is looping through the array like so:

{% for param in user_params %}
    {% if param==='add_user' %}
        do stuff in html
    {% endif %}
{% endfor %}

Ugly and full of holes, but will fit most use cases.

You're probably better off making a custom filter

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