> For the complete documentation index, see [llms.txt](https://docs.gaiodataos.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gaiodataos.com/gaio-dataos-spanish/herramientas/tareas/entrega/contenido/documentacion-de-nunjucks.md).

# Documentación de Nunjucks

**Nunjucks** es un potente motor de plantillas para JavaScript que permite generar contenido dinámico utilizando variables, filtros y estructuras de control.

### Contexto Disponible

En este entorno tienes acceso al siguiente objeto `context`:

```js
{
  params: {}, // Query parameters
  table: {    // Contains all available tables
    tableExample: [], // Each table is a list of objects
    anotherTable: []
  }
}
```

### Sintaxis Básica

**Variables**

Accede a variables utilizando doble llave:

```
{{ params.name }}
{{ table.tableExample[0].id }}
```

**Condicionales**

```
{% if params.showDetails %}
  Showing details for {{ params.id }}
{% else %}
  No details available
{% endif %}
```

**Bucles**

```
<ul>
{% for row in table.tableExample %}
  <li>{{ row.name }}: {{ row.value }}</li>
{% endfor %}
</ul>
```

### Filtros

Modifica variables utilizando el símbolo:

```
{{ params.name | upper }}
{{ params.date | date("YYYY-MM-DD") }}
{{ table.tableExample[0].amount | round(2) }}
```

#### Filtros Comunes

* `upper`, `lower` → Cambiar mayúsculas/minúsculas
* `trim` → Eliminar espacios
* `first`, `last` → Obtener primer/último elemento
* `length` → Obtener tamaño de arreglo o texto
* `sort` → Ordenar un arreglo
* `join` → Unir elementos de un arreglo

### Expresiones

```
{{ table.tableExample[0].price * 1.1 }}
{{ "Price: " + table.tableExample[0].price }}
{{ table.tableExample.length > 0 ? "Has items" : "Empty" }}
```

### Comentarios

```
{# This is a comment that won't be rendered #}
```

### Ejemplos Prácticos

**Formatear una Tabla Dinámica:**

```
<table>
  <thead>
    <tr>
      {% for key in Object.keys(table.tableExample[0]) %}
        <th>{{ key }}</th>
      {% endfor %}
    </tr>
  </thead>
  <tbody>
    {% for row in table.tableExample %}
      <tr>
        {% for key in Object.keys(table.tableExample[0]) %}
          <td>{{ row[key] }}</td>
        {% endfor %}
      </tr>
    {% endfor %}
  </tbody>
</table>
```

**Formato Condicional:**

```
{% for item in table.tableExample %}
  <div class="{% if item.value > 100 %}highlight{% endif %}">
    {{ item.name }}: {{ item.value }}
  </div>
{% endfor %}
```

**Usar Parámetros para Filtrar:**

```
{% if params.filter %}
  <h3>Filtered results for: {{ params.filter }}</h3>
  {% set filteredRows = table.tableExample | filter(row => row.category == params.filter) %}
  {% for row in filteredRows %}
    <div>{{ row.name }}</div>
  {% endfor %}
{% else %}
  <h3>All results</h3>
  {% for row in table.tableExample %}
    <div>{{ row.name }}</div>
  {% endfor %}
{% endif %}
```

**Acceder a Múltiples Tablas:**

```
<div>
  <h3>Table 1: {{ table.tableExample.length }} rows</h3>
  <ul>
    {% for row in table.tableExample %}
      <li>{{ row.name }}</li>
    {% endfor %}
  </ul>
  
  {% if table.anotherTable %}
  <h3>Table 2: {{ table.anotherTable.length }} rows</h3>
  <ul>
    {% for row in table.anotherTable %}
      <li>{{ row.title }}</li>
    {% endfor %}
  </ul>
  {% endif %}
</div>
```

**Agregación de Datos:**

```
{% set total = 0 %}
{% for item in table.tableExample %}
  {% set total = total + item.amount %}
{% endfor %}
<div>Total: {{ total }}</div>
```

Para información más detallada sobre todas las capacidades disponibles, consulta la [documentación oficial de Nunjucks](https://mozilla.github.io/nunjucks/templating.html).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gaiodataos.com/gaio-dataos-spanish/herramientas/tareas/entrega/contenido/documentacion-de-nunjucks.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
