首页 > 解决方案 > 树枝中的多个字符串值包含检查?

问题描述

我想检查变量中是否包含多个字符串值,到目前为止,我知道我可以检查变量中是否包含单个字符串值,但在多个值包含中没有找到任何内容。

谁能帮我吗?

我现在拥有的:

{% if "VenuesController::detailsAction" not in controllerAndActionName %}

我想做的事:

{% if ["VenuesController::detailsAction", "VmsController::indexAction", "DefaultController::headerAction"] not in controllerAndActionName %}

这可能吗?

标签: phpsymfonytwig

解决方案


不知道您是否可以直接在 中执行此操作twig,但解决方法应该是这样

{% set bool = true %}
{% for string in ["VenuesController::detailsAction", "VmsController::indexAction", "DefaultController::headerAction"] %}
    {% if string in controllerAndActionName %}
        {% set bool = false %}
    {% endif %}
{% endfor %}
{% if bool %}
    Foo
{% endif %}

演示


推荐阅读