Files
acai-scaffold/docs/twig-filters.md
Jordan 963174b4c4 Add complete Acai development documentation
- CLAUDE.md: expanded with critical rules, hook syntax, DB conventions, web-base endpoint
- docs/modular-system.md: modules, general sections, global vars, multiv2
- docs/builder-fields.md: all field types, c-if/c-for/c-class, c-form, built-in components
- docs/twig-filters.md: get, hook, module, queryDB, imagec, translate, raw, etc.
- docs/hooks-and-api.md: PHP hooks, CmsApi CRUD, table schemas, field formats
- docs/css-js-conventions.md: Tailwind, BEM, CSS vars, Vue 3 integration, CmsApi JS

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 18:53:10 +00:00

2.4 KiB

Twig Filters Reference

Acai uses Twig filters (with | pipe syntax). Never use Twig functions — only filters are supported.

Database Queries

get — Query Table

{# All records #}
{% set products = 'productos' | get() %}

{# With WHERE #}
{% set active = 'productos' | get({activo: 1}) %}

{# With WHERE + ORDER + LIMIT #}
{% set latest = 'noticias' | get({publicado: 1}, 'fecha DESC', 6) %}

{# Single record (first result) #}
{% set product = 'productos' | get({num: 42}) %}
{{ product[0].nombre }}

queryDB — Raw SQL Query

{% set results = 'SELECT * FROM cms_productos WHERE precio > 100 ORDER BY precio ASC' | queryDB() %}

Note: Raw SQL uses the full table name WITH cms_ prefix.

Module & Hook Execution

hook — Execute PHP Hook

{# Call hook and output result #}
{{ 'hooks/module_id/' | hook({param1: 'value', param2: variable}) }}

{# Capture into variable #}
{% set result = 'hooks/module_id/' | hook({action: 'getData'}) %}

module — Render Another Module

{{ 'other_module_id' | module({param1: value1}) }}

Text & Content

translate — Translation

{{ 'Hello' | translate }}
{{ variable | translate }}

raw — Render HTML Without Escaping

{{ record.description | raw }}

truncate — Text Truncation

{{ record.description | truncate(150) }}

json_decode — Parse JSON String

{% set data = jsonString | json_decode %}
{{ data.key }}

Images

imagec — Image Optimization/Resize

{# Resize to width #}
<img src="{{ record.image[0].urlPath | imagec(400) }}" />

{# In srcset #}
<img src="{{ record.image[0].urlPath | imagec(800) }}"
     srcset="{{ record.image[0].urlPath | imagec(400) }} 400w,
             {{ record.image[0].urlPath | imagec(800) }} 800w" />

Operators & Syntax

Concatenation

Twig uses ~ for string concatenation (not . or +):

{{ 'Hello ' ~ name ~ '!' }}
{% set url = '/products/' ~ product.slug ~ '/' %}

Ternary / Default

{{ title | default('Default Title') }}
{{ isActive ? 'active' : 'inactive' }}

Comparisons in Twig

{% if items | length > 0 %}
{% if type == 'premium' %}
{% if name is not empty %}

Note: In c-if attributes, use = (single equals) for equality. In Twig {% if %} blocks, use == (double equals).