# Aide jinja

**URL:** <https://forum.hacf.fr/t/aide-jinja/50141>\
**Category:** Entraide Home Assistant\
**Tags:** jinja\
**Created:** [Octobre 25, 2024, 9:55 UTC](https://forum.hacf.fr/t/aide-jinja/50141 "2024-10-25T09:55:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miralant](https://forum.hacf.fr/user_avatar/forum.hacf.fr/miralant/32/42625_2.png) [@miralant](https://forum.hacf.fr/u/miralant)\
**Post date:** [Octobre 25, 2024, 9:55 UTC](https://forum.hacf.fr/t/aide-jinja/50141/1 "2024-10-25T09:55:43Z")

</div>

Bonjour à tous,

Je butte sur les listes en jinja. Je ne comprends pas pourquoi le tableau est vide ☹

Le but est de remonter les valeurs impaires dans la liste des horaires d’un scheduler.

auriez vous une idée.

```auto
{% set timeslots_string = "['00:00:00 - 07:20:00', '07:20:00 - 09:20:00', '09:20:00 - 19:30:00', '19:30:00 - 21:30:00', '21:30:00 - 00:00:00']" %}
{% set timeslots_list = timeslots_string | replace("'", '"') | from_json %}
{% set odd_timeslots = [] %}
{% for index in range(0, timeslots_list | length) %}
  {% if index % 2 != 0 %}
  {% set odd_timeslots= odd_timeslots + [timeslots_list[index]] %}
  {% endif %}
{% endfor %}

{{odd_timeslots}}

```

Merci

---

<div class="post-metadata">

**Author:** ![bastgau](https://forum.hacf.fr/user_avatar/forum.hacf.fr/bastgau/32/46175_2.png) [@bastgau](https://forum.hacf.fr/u/bastgau)\
**Post date:** [Octobre 25, 2024, 10:07 UTC](https://forum.hacf.fr/t/aide-jinja/50141/2 "2024-10-25T10:07:41Z")

</div>

Bonjour.

Il y a un problème avec la portée de tes variables. Il faut passer par des namespaces si tu veux modifier un tableau dans une boucle.

Je pourrais donner un exemple si besoin.

---

<div class="post-metadata">

**Author:** ![miralant](https://forum.hacf.fr/user_avatar/forum.hacf.fr/miralant/32/42625_2.png) [@miralant](https://forum.hacf.fr/u/miralant)\
**Post date:** [Octobre 25, 2024, 11:41 UTC](https://forum.hacf.fr/t/aide-jinja/50141/3 "2024-10-25T11:41:24Z")

</div>

Yes, c’est bon merci

> **[Jinja2 Namespaces and Variable Scope](https://serverascode.com/2018/03/15/jinja2-namespaces.html)**
>
> I have been doing some Network automation lately, specifically using the Juniper vSRX and generating config templates via Ansible.
