Skip to content

Tag: twig

How to escape Twig like variables on JS

I need to escape some JS twig-like variables in a twig template, but I couldn’t find anything about how to do that. This variables are used in a js templating plugin that uses the same pattern as twig for variables which is causing the twig rendering to fail Unexpected token “punctuation” of…

Symfony form collection rendering

I’m using symfony 2.3 I have form with field of type “collection” Visualization code in twig: Everything work, expect when form.fields is empty. Then nothing is visualized in twig loop, witch is fine. But at the end of the form there is “label” for the element “form.fields&…

Twig get url parameter with []

I have an url like : MYURL?filter[_per_page]=25&filter[name][value]=hello How can i get these parameters with twig ? I’m trying {{ app.request.get(‘filter[_per_page]’) }} but it’s always empty… Thanks ! Edit : I’m in javascript an i want to assign this result to a javas…

Getting array keys in Twig? (Symfony)

Is it possible to get the key of an array in Twig (in Symfony)? For example if I have an array of: Is it possible in Twig to print: key1: value1 key2: value2 Thanks Answer Try following format: More Information on Offical Twig about Iterating over Keys and Values https://twig.symfony.com/doc/3.x/tags/for.html…

output printer ESC codes from twig in Symfony

I have a system that uses Symfony, and is connected to a (citizen ct-s2000) POS printer. What I currently do is render the string to send to the printer, using the twig service: and send this to the printer using fwrite, after that I feed the paper 1 line and cut the paper using: This all works like a charm,

Twig tag include vs function include

Twig’s documentation for tag include looks very similar to that of function include. Tag include: Function include: Can somebody point out in what circumstances, one is preferred over the other? Thanks! Answer {{ include() }} Was introduce in Symfony 2.2: Using a function allows you to do whatever you w…