Bootstrap FreeKB - Jinja - Getting Started with Variables
Jinja - Getting Started with Variables

Updated:   |  Jinja articles

set is used to create a variable in Jinja.

{% set foo = "bar" %}
foo = {{ foo }}

 

In this example, the output should be

foo = bar

 

The + (plus) character is used similar to how the plus character is used in Python, to toggle between literal strings and Jinja variables.

{% set name = "John Doe" %}
{% set greeting = " Hello " + name %}

 

Let's say you set multiple variables.

{% set month = '01' %}
{% set day   = '10' %}
{% set year  = '2023' %}

 

Here is how you could create a variable using multiple other variables.

{% set date = month+day+year %}

 

Of, if you have an int (integer) object, you may want to use ~ (tilde) instead of + (plus) as ~ (tilde) will convert the int object into a string.

{% set mynumber = " Your number is " ~ number %}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter a18464 in the box below so that we can be sure you are a human.