twig - 匹配子串是 Twig

标签 twig drupal-views drupal-8

我正在开发一个新的 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/

相关文章:

php - Symfony 翻译不起作用

php - 如何迭代 Twig 模板中 findBy Doctrine 查询的数组结果

php - Drupal View 自动过滤器

drupal-7 - Drupal 7 View 按节点的分类术语过滤

android - 性能 : Android Webview vs Views Datasource + parsing JSON

php - 使用 Slim Framework 和 Laravel 的 Eloquent ORM 进行分页

Drupal 8 - 在 Twig 中获取节点网址

php - 如何在 Drupal 8 表单中获取触发按钮 id

linux - 德鲁帕尔 8 : How to use private file system for node

drupal - html.html.twig 中的内联 css |德鲁巴 8