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>
This commit is contained in:
118
docs/twig-filters.md
Normal file
118
docs/twig-filters.md
Normal file
@@ -0,0 +1,118 @@
|
||||
# Twig Filters Reference
|
||||
|
||||
Acai uses Twig **filters** (with `|` pipe syntax). Never use Twig functions — only filters are supported.
|
||||
|
||||
## Database Queries
|
||||
|
||||
### `get` — Query Table
|
||||
|
||||
```twig
|
||||
{# 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
|
||||
|
||||
```twig
|
||||
{% 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
|
||||
|
||||
```twig
|
||||
{# 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
|
||||
|
||||
```twig
|
||||
{{ 'other_module_id' | module({param1: value1}) }}
|
||||
```
|
||||
|
||||
## Text & Content
|
||||
|
||||
### `translate` — Translation
|
||||
|
||||
```twig
|
||||
{{ 'Hello' | translate }}
|
||||
{{ variable | translate }}
|
||||
```
|
||||
|
||||
### `raw` — Render HTML Without Escaping
|
||||
|
||||
```twig
|
||||
{{ record.description | raw }}
|
||||
```
|
||||
|
||||
### `truncate` — Text Truncation
|
||||
|
||||
```twig
|
||||
{{ record.description | truncate(150) }}
|
||||
```
|
||||
|
||||
### `json_decode` — Parse JSON String
|
||||
|
||||
```twig
|
||||
{% set data = jsonString | json_decode %}
|
||||
{{ data.key }}
|
||||
```
|
||||
|
||||
## Images
|
||||
|
||||
### `imagec` — Image Optimization/Resize
|
||||
|
||||
```twig
|
||||
{# 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 `+`):
|
||||
|
||||
```twig
|
||||
{{ 'Hello ' ~ name ~ '!' }}
|
||||
{% set url = '/products/' ~ product.slug ~ '/' %}
|
||||
```
|
||||
|
||||
### Ternary / Default
|
||||
|
||||
```twig
|
||||
{{ title | default('Default Title') }}
|
||||
{{ isActive ? 'active' : 'inactive' }}
|
||||
```
|
||||
|
||||
### Comparisons in Twig
|
||||
|
||||
```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).
|
||||
Reference in New Issue
Block a user