在Twig中,您可以轻松检查字符串starts with或ends 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.
我尝试了各种不同的组合:
{% 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)
| 归档时间: |
|
| 查看次数: |
2669 次 |
| 最近记录: |