Documentation is being updated. Some sections may not reflect the latest features.
Looking for step-by-step guides? Explore Tutorials →

Template Syntax

Ubex uses Pongo2, a powerful Django/Jinja2-style template engine. This gives you full control over how data flows through your workflows.

Basic Variables

Use double curly braces to output variables:

{{ variable_name }}
{{ user.name }}
{{ items[0].title }}

Filters

Transform values using filters with the pipe | operator:

{{ name | upper }}
{{ text | lower }}
{{ price | floatformat:2 }}
{{ items | length }}
{{ description | truncatechars:100 }}
{{ html_content | safe }}
{{ list | join:", " }}
{{ date | date:"2006-01-02" }}
{{ value | default:"N/A" }}

Common Filters

Filter Description Example
upper Uppercase text {{ name | upper }}
lower Lowercase text {{ name | lower }}
title Title Case {{ name | title }}
length Count items/characters {{ items | length }}
default Fallback value {{ value | default:"none" }}
join Join array elements {{ tags | join:", " }}
first First item {{ items | first }}
last Last item {{ items | last }}
truncatechars Limit characters {{ text | truncatechars:50 }}
safe Render HTML {{ html | safe }}
floatformat Format decimals {{ price | floatformat:2 }}

Conditionals

Use {% if %} for conditional logic:

{% if user.is_premium %}
  Welcome back, premium member!
{% elif user.is_trial %}
  Your trial ends in {{ user.trial_days }} days.
{% else %}
  Sign up for premium features.
{% endif %}

Comparison Operators

{% if count > 10 %}...{% endif %}
{% if status == "active" %}...{% endif %}
{% if name != "" %}...{% endif %}
{% if score >= 80 %}...{% endif %}
{% if items and items | length > 0 %}...{% endif %}
{% if not is_disabled %}...{% endif %}

Logical Operators

{% if is_admin and is_active %}...{% endif %}
{% if is_free or is_trial %}...{% endif %}
{% if not is_blocked %}...{% endif %}

Loops

Use {% for %} to iterate over arrays:

{% for item in items %}
  - {{ item.name }}: {{ item.value }}
{% endfor %}

Loop Variables

Inside a loop, you have access to special variables:

{% for user in users %}
  {{ forloop.Counter }}: {{ user.name }}
  {% if forloop.First %}(first item){% endif %}
  {% if forloop.Last %}(last item){% endif %}
{% endfor %}
Variable Description
forloop.Counter Current iteration (1-indexed)
forloop.Counter0 Current iteration (0-indexed)
forloop.First True if first iteration
forloop.Last True if last iteration
forloop.Revcounter Iterations remaining

Empty Loops

Handle empty arrays gracefully:

{% for item in items %}
  {{ item.name }}
{% empty %}
  No items found.
{% endfor %}

Practical Examples

Building a Prompt with Context

You are analyzing customer feedback.

{% for review in reviews %}
Review #{{ forloop.Counter }}:
Rating: {{ review.rating }}/5
Comment: {{ review.text | truncatechars:200 }}

{% endfor %}

Summarize the overall sentiment and key themes.

Conditional API Request Body

{
  "user": "{{ user.email }}",
  "plan": "{{ plan | default:"free" }}",
  {% if include_metadata %}
  "metadata": {
    "source": "{{ source }}",
    "timestamp": "{{ timestamp }}"
  }
  {% endif %}
}

Dynamic Email Content

Hi {{ user.name | title }},

{% if order.status == "shipped" %}
Great news! Your order #{{ order.id }} has shipped.
Tracking: {{ order.tracking_number }}
{% elif order.status == "processing" %}
Your order #{{ order.id }} is being prepared.
{% else %}
Your order #{{ order.id }} is confirmed.
{% endif %}

Items ordered:
{% for item in order.items %}
- {{ item.quantity }}x {{ item.name }} - ${{ item.price | floatformat:2 }}
{% endfor %}

Total: ${{ order.total | floatformat:2 }}

Generating SQL Queries

SELECT * FROM users
WHERE status = 'active'
{% if department %}
  AND department = '{{ department }}'
{% endif %}
{% if min_score %}
  AND score >= {{ min_score }}
{% endif %}
ORDER BY created_at DESC
LIMIT {{ limit | default:100 }}

Tips

  • Use {{ variable | default:"fallback" }} to handle missing values
  • Use {% if variable %} to check if a variable exists and is not empty
  • Filters can be chained: {{ name | lower | truncatechars:20 }}
  • Whitespace inside {{ }} and {% %} is ignored
AI AssistantPowered by Ubex
Beta
Ask me anything about Ubex workflows, nodes, or the API.