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]}}
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
Use this: {% set myVal = 50 %} {% for item in items %} {% set myVal = myVal + 10 %} {% endfor %} For declaring, setting values, setting blocks/forms, etc. you must use {% %}. For output, there is {{ }}
In fact there’s no need to set an extra variable. For two nested loops twig provides the so called parent.loop context. To access the parents loop.index do this: {% for i in range(0, 3) %} {% for j in range(0, 9) %} {{ loop.parent.loop.index + loop.index }} {% endfor %} {% endfor %} Also refer … Read more
The way to do it is: {% set c = a ~ b %}
Can be done with the test iterable, added in twig1.7, as Wouter J stated in the comment : {# evaluates to true if the users variable is iterable #} {% if users is iterable %} {% for user in users %} Hello {{ user }}! {% endfor %} {% else %} {# users is probably … Read more
A hyphen (or dash) at the end of a Twig block means to trim trailing whitespace, at the beginning, leading whitespace. Both means… both. See the Whitespace Control section of the docs; their example: {% set value=”no spaces” %} {#- No leading/trailing whitespace -#} {%- if true -%} {{- value -}} {%- endif -%} {# … Read more
Just use the length filter on the whole array. It works on more than just strings: {{ notcount|length }}
check this Twig Reference. You can do it that simple: {% if (a or b) %} … {% endif %}
I know this is a little late answer, but I hope anyone who looks this question get helped. In PhpStorm, almost everything can be configured but a little tricky and takes some learning curve. It’s very common behaviour that select a word and type single quote (or double quote) to surround it. Hello World ‘Hello … Read more