Twig:检查字符串是不是以另一个字符串结尾

dun*_*can 5 twig

在Twig中,您可以轻松检查字符串starts withends with其他字符串:

http://twig.sensiolabs.org/doc/templates.html#comparisons

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

{% if 'Fabien' ends with 'n' %}{% endif %}
Run Code Online (Sandbox Code Playgroud)

但是,如何判断字符串是否以另一个字符串结尾?我正在做一些像检查文件名不会结束的事情.jpg.

dun*_*can 9

我尝试了各种不同的组合:

{% 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 %}
Run Code Online (Sandbox Code Playgroud)

最后这就是我的工作:

{% if not (filename ends with '.jpg') %}
Run Code Online (Sandbox Code Playgroud)