Skip to main content

Fundamental Principles of Jinja

Basic Structure

Jinja works by combining static text with dynamic elements delimited by specific syntaxes:
DelimiterFunctionExample
{{ ... }}Variable InsertionHello {{ client.name }}
{% ... %}Logical Instructions{% if hour > 18 %}Good evening{% else %}Hello{% endif %}
{# ... #}Comments (not rendered){# This text does not appear in the final prompt #}

Types of Variables

Variables can contain different types of data:
{# Simple Variables #}
{{ client_name }}         {# String #}
{{ client_age }}          {# Number #}
{{ is_premium }}          {# Boolean #}

{# Structured Variables #}
{{ client.address.city }}         {# Accessing nested properties #}
{{ client['address']['city'] }}   {# Accessing nested properties #}
{{ products[0].name }}            {# Accessing list items #}

Conditions (if/elif/else)

Conditions allow for adapting the prompt according to different contexts:
{% if system.phone is defined %}
   Can you confirm that your number is {{ system.phone }}?
{% else %}
   Can you give me your number?
{% endif %}
Use nested conditions to manage complex scenarios, but maintain a readable structure to facilitate maintenance.

Additional Resources

Jinja Documentation

For complete documentation on Jinja syntax, please refer to the documentation.