In Twig you can easily check if a string starts with
or ends with
another string:
http://twig.sensiolabs.org/doc/templates.html#comparisons
{% if 'Fabien' starts with 'F' %}{% endif %}
{% if 'Fabien' ends with 'n' %}{% endif %}
However, how do you find out if a string doesn't end with another one? I'm doing something like checking a filename doesn't end in .jpg
for instance.
If the delimiter is an empty string, then value will be split by equal chunks. Length is set by the limit argument (one character by default). Internally, Twig uses the PHP explode or str_split (if delimiter is empty) functions for string splitting.
You can get the current URL in Twig/Silex 2 like this: global. request. attributes. get('_route') .
Twig is a modern template engine for PHP Fast: Twig compiles templates down to plain optimized PHP code. The overhead compared to regular PHP code was reduced to the very minimum. Secure: Twig has a sandbox mode to evaluate untrusted template code.
I'd tried various combinations like these unsuccesfully:
{% if not filename ends with '.jpg' %}
{% if filename ends with '.jpg' is false %}
{% if (filename ends with '.jpg') is false %}
{% if (filename ends with '.jpg') not true %}
In the end this was what I got to work:
{% if not (filename ends with '.jpg') %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With