Skip to content
Advertisement

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 value “:” (“end of print statement” expected) in

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”. Only label. Workaround: If there are elements, they will be rendered in the

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 javascript variable like : var param = “{{ app.request.get(‘filter[_per_page]’) }}”; Answer You must manage as an array accessing to

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#iterating-over-keys-and-values

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 want with the output (which is not possible with a tag),

How to retrieve all Variables from a Twig Template?

Is it possible to retrieve all variables inside a Twig template with PHP? Example someTemplate.twig.php: Now I want to do something like this: $variables should now contain “name” and “email”. The reason I want to do this is that I am working on a CMS system where my twig templates and variables are dynamically set by my users and they

Advertisement