匹配子串是树枝

Match sub-string is the twig

我正在开发一个新的 drupal8 网站,但我不知道自己做错了什么!我需要做的就是查找名为 output 的变量中是否存在子字符串。

{% 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 一个工作示例。

希望对您有所帮助