È inoltre possibile definire un costume filtro come il filtro |append
di Liquid nella tua istanza Twig che fa la stessa cosa.
$loader = new Twig_Loader_Filesystem('./path/to/views/dir');
$twig = new Twig_Environment($loader);
...
...
$twig->addFilter(new Twig_SimpleFilter('append', function($val, $append) {
return $val . $append;
}));
Con conseguente seguente markup:
{% set pants = 'I\'m wearing stretchy pants!' %}
{% set part2 = ' and they\'re friggin\' comfy!' %}
{% set pants = pants|append(part2) %}
{{ pants }}
{# result: I'm wearing stretchy pants! and they're friggin' comfy! #}
IMHO trovo l'esempio precedente più intuitiva rispetto alla ~
combinatore, soprattutto quando si lavora su una base di codice comune in cui le persone che non conoscono la sintassi potrebbe ottenere un po ' mischiato.
Haha, che soluzione sciocca ma funziona. Grazie :) – Jon