我正在开发一个新的 drupal8 网站,但我不知道我做错了什么!我需要做的就是查找名为“输出”的变量中是否存在子字符串。
{% if ((output|raw matches '\b<div class="image"><\\div>\b') == true) %}
<h1>this is a test</h1>
{% endif %}
最佳答案
您可以简化 if
表达式,删除 true
比较(在 matches 语句中隐含)。所以尝试简单地这样做:
{% if output matches '\b<div class="image"></div>\b' %}
<h1>this is a test</h1>
{% endif %}
Here一个工作示例。
希望这有帮助
关于twig - 匹配子串是 Twig ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39989436/