The ems project heavily uses TWIG.
- ElasticMS Admin uses twig for: custom dashboards, views, actions, postprocessing, ..
- ElasticMS Web uses twig for creating webpages, redirect, pdf exports, file serving
- Twig
- Twig cheatsheet
- Symfony cheatsheet
- elasticMS Common Bundle Extension for both ElasticMS Admin and ElasticMS Web
Tags | ||||
---|---|---|---|---|
apply | deprecated | flush | import | use |
autoescape | do | for | include | verbatim |
block | embed | from | macro | with |
cache | extends | if | set |
Functions | |||
---|---|---|---|
attribute | cycle | include | random |
block | date | max | range |
constant | dump | min | source |
country_timezones | html_classes | parent | template_from_string |
Tests | ||
---|---|---|
constant | empty | null |
defined | even | odd |
divisibleby | iterable | sameas |
Operators |
---|
in |
is |
Math (+, -, /, %, //, *, **) |
Logic (and, or, not, (), b-and, b-xor, b-or) |
Comparisons (==, !=, <, >, >=, <=, ===, starts with, ends with, matches) |
Others (.., , ~, ., [], ?:, ??) |
Tags |
---|
trans |
trans_default_domain |
Filters | |
---|---|
humanize | trans |
yaml_encode | yaml_dump |
serialize |
The common's twig filters and functions are available in both ElasticMS Admin and in ElasticMS Web
This filter parses a string and returns a Symfony DomCrawler
Useful to extract content from a html string: {% set firstP = data.body_fr|ems_dom_crawler.filter('p').first.text %}
Another example for adding the class img-fluid
to all img tags:
{% set crawler = body|emsch_routing|ems_dom_crawler %}
{% for img in crawler.filter('img') %}
{% if img.getAttribute('class') == '' %}
{% do img.setAttribute('class', 'img-fluid') %}
{% endif %}
{% endfor %}
{{ crawler.filter('body').html()|raw }}
Returns true if the template exists. Also for only locally defined templates.
{% set templateExists = ems_template_exists('@EMSCH/template/example.twig') %}