Twig Access Array Index?
Just before posting this I realized, that’s exactly what you can do, but as I didn’t find the answer anywhere in the docs or google (correct me if I’m wrong), I’ve posted this anyway. {{numbers[0]}}
Just before posting this I realized, that’s exactly what you can do, but as I didn’t find the answer anywhere in the docs or google (correct me if I’m wrong), I’ve posted this anyway. {{numbers[0]}}
You were going on right track, what you missed is just to pass someVariable as a parameter to trans() in your Twig file as: <h2>{{ “follow.us.in.twitter”|trans({‘%someVariable%’: someVariable}, “workend”) }}</h2> Now your message in Yml file should be as: follow.us.in.twitter: Hola, Follow %someVariable% en Twitter This should work. For more details and clarity you can refer … Read more
you can do it with {{ form_widget(formView._token) }}
Yes, there is, it is called first. The rest is copied from the documentation. New in version 1.12.2: The first filter was added in Twig 1.12.2. The first filter returns the first “element” of a sequence, a mapping, or a string: {{ [1, 2, 3, 4]|first }} {# outputs 1 #} {{ { a: 1, … Read more
{% if your_variable is null or your_variable is empty %} should check whether the variable is null or empty. If you want to see if it’s not null or empty just use the notoperator. {% if foo is not null and foo is not empty %} See the docs: empty null “is” operator logical operators … Read more
The easiest way is to output the variable delimiter ({{) by using a variable expression: {{ ‘{{‘ }} Alternatives (used when you have to escape too much) are raw (verbatim since 1.12) blocks: {% raw %} <ul> {% for item in seq %} <li>{{ item }}</li> {% endfor %} </ul> {% endraw %} Actually, it’s … Read more
You can solve it like this, if you want to display a certain block only if it has content. Hope, this is what you’re looking for. Example index.html.twig {% set _block = block(‘dynamic’) %} {% if _block is not empty %} {{ _block|raw }} {% endif %} Example part.html.twig {% extends “index.html.twig” %} {% block … Read more
Have you just tried this: attribute(item2, key).title
Try this one: {% extends intro == ‘false’ ? ‘UdoWebsiteBundle::layout.html.twig’ : ‘UdoWebsiteBundle::layout_true.html.twig’ %} Idea taken from here: http://jorisdewit.ca/2011/08/27/extending-different-layouts-for-ajax-requests-in-twig-symfony2/
You need to add the _token in your form i.e {{ form_row(form._token) }} As of now your form is missing the CSRF token field. If you use the twig form functions to render your form like form(form) this will automatically render the CSRF token field for you, but your code shows you are rendering your … Read more