Nunjucks Documentation

Nunjucks is a powerful templating engine for JavaScript that allows you to create dynamic content using variables, filters, and control structures.

Available Context

In this environment, you have access to the following context object:

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

Basic Syntax

Variables

Access variables using double curly braces:

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

Conditionals

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

Loops

Filters

Modify variables with filters using the pipe symbol:

Common filters:

  • upper, lower: Change case

  • trim: Remove whitespace

  • first, last: Get first/last item

  • length: Get length of array/string

  • sort: Sort an array

  • join: Join array elements

Expressions

Comments

Practical Examples

Formatting a table:

Conditional formatting:

Using params for filtering:

Accessing multiple tables:

Aggregating data:

For more information, visit the Nunjucks documentation.

Last updated