Twig 为什么这个细枝语句不起作用?

Twig 为什么这个细枝语句不起作用?,twig,Twig,细枝“in”语句可能存在问题。以下是几个例子: 为什么这个能工作 {% set curPath = 'http://example.com' %} {% if 'exa' in curPath %} Inside The If Statement {% endif %} 为什么这个不起作用? {% set curPath = url('<current>') %} {{ curPath }} // prints 'example.com' {% i

细枝“in”语句可能存在问题。以下是几个例子:

为什么这个能工作

{% set curPath = 'http://example.com' %} 
{% if 'exa' in curPath %}
   Inside The If Statement
{% endif %}
为什么这个不起作用?

   {% set curPath =  url('<current>') %}
    {{ curPath }} // prints 'example.com' 
    {% if 'exa' in curPath %}
       Inside The If Statement
    {% endif %} 
{%set curPath=url(“”)%}
{{curPath}}//打印'example.com'
{%if curPath%中的“exa”}
在If语句中
{%endif%}

你能试试
{{dump(curPath)}}
吗。Prolly
url
返回一个对象而不是字符串。通过调用
{{curPath}
您实际上正在执行
{{curPath.toString()}
。如果是这种情况,你可以通过执行
{%If'exa in curPath~''%}
'exa in curPath~'来“解决”这个问题,我甚至不需要把eva放在报价中。在你知道它之前,细枝将成为它自己的编程语言,如果它还没有那么成熟的话。。。谢谢@DarkBee。。。