“Begins with” in Twig template

You can do that directly in Twig now:

{% if 'World' starts with 'F' %}
{% endif %}

“Ends with” is also supported:

{% if 'Hello' ends with 'n' %}
{% endif %}

Other handy keywords also exist:

Complex string comparisons:

{% if phone matches '{^[\\d\\.]+$}' %} {% endif %}

(Note: double backslashes are converted to one backslash by twig)

String contains:

{{ 'cd' in 'abcde' }}
{{ 1 in [1, 2, 3] }}

See more information here: http://twig.sensiolabs.org/doc/templates.html#comparisons

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)