Documentation is being updated. Some sections may not reflect the latest features.

Template Syntax

Ubex utiliza Pongo2, un potente motor de plantillas al estilo Django/Jinja2. Esto le da control total sobre cómo fluyen los datos a través de sus workflows.

Variables básicas

Use llaves dobles para mostrar variables:

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

Filtros

Transforme valores usando filtros con el operador pipe |:

{{ 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" }}

Filtros comunes

Filtro Descripción Ejemplo
upper Texto en mayúsculas {{ name | upper }}
lower Texto en minúsculas {{ name | lower }}
title Capitalización de título {{ name | title }}
length Contar elementos/caracteres {{ items | length }}
default Valor de respaldo {{ value | default:"none" }}
join Unir elementos de un array {{ tags | join:", " }}
first Primer elemento {{ items | first }}
last Último elemento {{ items | last }}
truncatechars Limitar caracteres {{ text | truncatechars:50 }}
safe Renderizar HTML {{ html | safe }}
floatformat Formatear decimales {{ price | floatformat:2 }}

Condicionales

Use {% if %} para lógica condicional:

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

Operadores de comparación

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

Operadores lógicos

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

Bucles

Use {% for %} para iterar sobre arrays:

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

Variables de bucle

Dentro de un bucle, tiene acceso a variables especiales:

{% for user in users %}
  {{ forloop.Counter }}: {{ user.name }}
  {% if forloop.First %}(first item){% endif %}
  {% if forloop.Last %}(last item){% endif %}
{% endfor %}
Variable Descripción
forloop.Counter Iteración actual (índice desde 1)
forloop.Counter0 Iteración actual (índice desde 0)
forloop.First True en la primera iteración
forloop.Last True en la última iteración
forloop.Revcounter Iteraciones restantes

Bucles vacíos

Gestione arrays vacíos de forma elegante:

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

Ejemplos prácticos

Construir un prompt con contexto

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.

Cuerpo condicional de una solicitud API

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

Contenido dinámico de correo electrónico

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 }}

Generar consultas SQL

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 }}

Consejos

  • Use {{ variable | default:"fallback" }} para manejar valores faltantes
  • Use {% if variable %} para comprobar si una variable existe y no está vacía
  • Los filtros se pueden encadenar: {{ name | lower | truncatechars:20 }}
  • Los espacios en blanco dentro de {{ }} y {% %} se ignoran
AI AssistantPowered by Ubex
Beta
Ask me anything about Ubex workflows, nodes, or the API.
~/

Hola 👋

¿Cómo podemos ayudarte hoy?