> 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-portuguese/tools/tarefas/entrega/conteudo/documentacao-do-nunjucks.md).

# Documentação do Nunjucks

**Nunjucks** é um poderoso mecanismo de templates para JavaScript que permite criar conteúdo dinâmico utilizando variáveis, filtros e estruturas de controle.

***

### Contexto Disponível

Neste ambiente, você tem acesso ao seguinte objeto `context`:

```javascript
{
  params: {}, // Parâmetros de query
  table: {    // Contém todas as tabelas disponíveis
    tableExample: [], // Cada tabela é uma lista de objetos
    anotherTable: []
  }
}
```

### Sintaxe Básica

#### Variáveis

Acesse variáveis utilizando chaves duplas:

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

***

#### Condicionais

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

***

#### Loops

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

***

#### Filtros

Modifique variáveis utilizando filtros com o símbolo pipe (`|`):

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

Filtros comuns:

* `upper`, `lower` – Alterar maiúsculas/minúsculas
* `trim` – Remover espaços em branco
* `first`, `last` – Obter primeiro/último item
* `length` – Obter tamanho de array/string
* `sort` – Ordenar um array
* `join` – Unir elementos de um array

#### Expressões

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

***

#### Comentários

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

***

### Exemplos Práticos

#### Formatando uma tabela

```nunjucks
<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>
```

***

#### Formatação Condicional

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

***

#### Utilizando `params` para filtragem

```nunjucks
{% 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 %}
```

#### Acessando múltiplas tabelas

```nunjucks
<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>
```

***

#### Agregando dados

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

Para mais informações, consulte [a documentação oficial do 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-portuguese/tools/tarefas/entrega/conteudo/documentacao-do-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.
