'Twig: Unexpected token "name" of value "as" ("end of statement block" expected)

When i run a Twig Lint test localy using CLI on a file, i get no warning. But, my Gitlab pipeline returns a KO for the same file at the Twig-Lint stage:

Unexpected token "name" of value "as" ("end of statement block" expected)

Here is my code:

{% for subItem in item.subItems %}
    {% if subItem.subIndex is same as eaConst('SUBMENU_INDEX', ea.request)|int 
       and subItem.linkUrl is not same as menuItemUrl
    %}
       {% set submenuItemLabel = subItem.label %}
       {% set submenuItemUrl = subItem.linkUrl %}
    {% endif %}
{% endfor %}

I have tried this on the 'if' statement, but the error is still here:

{% if subItem.subIndex is same as(eaConst('SUBMENU_INDEX', ea.request)|int)
    and subItem.linkUrl is not same as(menuItemUrl)
%}

For me everything is correct, i can't figure out what's wrong. Thank you for your help.

EDIT: Here is the pipeline test failure https://gitlab.com/solo-projects3/ep-portfolio/-/jobs/2092671708



Solution 1:[1]

Well, as i didn't find any solution, i finally seperated the condition into 2 different 'if' statements:

{% if subItem.subIndex is same as(eaConst('SUBMENU_INDEX', ea.request)|int) %}
    {% if subItem.linkUrl is not same as(menuItemUrl) %}
         ...
    {% endif %}
{% endif %}

It is verbose, but it works. If anyone have a better solution, i am still interested, as i am facing this issue quite often.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Edouard