Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error processing inline-if twig statement #37

rbrv opened this issue Mar 10, 2020 · 8 comments

Error processing inline-if twig statement #37

rbrv opened this issue Mar 10, 2020 · 8 comments


Copy link

rbrv commented Mar 10, 2020

Got this error while testing:


[error] templates/shop/products/_item.twig: Error: ERROR: Invalid token
[error]   2 |                         <select name="purchasableId" id="purchasableId" class="purchasableId">
[error]   3 |                             {%- for purchasable in product.getVariants() -%}
[error] > 4 |                                 <option {% if not purchasable.isAvailable %}disabled{% endif %}>
[error]     |                                         ^
[error]   5 |                                     {{ purchasable.description }}
[error]   6 |                                     {{
[error]   7 |                                         purchasable.salePrice|commerceCurrency(
[error] A tag must consist of attributes or expressions. Twig Tags are not allowed.
[error]     at TokenStream.error (/mytestproject/node_modules/melody-parser/lib/index.js:1359:22)
[error]     at Parser.error (/mytestproject/node_modules/melody-parser/lib/index.js:830:21)
[error]     at Parser.matchAttributes (/mytestproject/node_modules/melody-parser/lib/index.js:818:22)
[error]     at Parser.matchElement (/mytestproject/node_modules/melody-parser/lib/index.js:726:14)
[error]     at Parser.parse (/mytestproject/node_modules/melody-parser/lib/index.js:627:32)
[error]     at Object.parse (/mytestproject/node_modules/melody-extension-core/lib/index.js:1187:36)
[error]     at Parser.matchTag (/mytestproject/node_modules/melody-parser/lib/index.js:857:29)
[error]     at Parser.parse (/mytestproject/node_modules/melody-parser/lib/index.js:610:32)
[error]     at Parser.matchElement (/mytestproject/node_modules/melody-parser/lib/index.js:736:41)
[error]     at Parser.parse (/mytestproject/node_modules/melody-parser/lib/index.js:627:32)

Source file

                        <select name="purchasableId" id="purchasableId" class="purchasableId">
                            {%- for purchasable in product.getVariants() -%}
                                <option {% if not purchasable.isAvailable %}disabled{% endif %}>
                                    {{ purchasable.description }}
                            {%- endfor -%}


    "tabWidth": 4,
    "plugins": ["./node_modules/prettier-plugin-twig-melody"],
    "twigMultiTags": [
Copy link

twbartel commented Mar 16, 2020

Hi @rbrv, this is a limitation in the Melody parser (separate project). I cannot give an ETA for a fix, but issues like that can be worked around by doing something like

{%- for purchasable in product.getVariants() -%}
    {% set optionDisabled = not purchasable.isAvailable ? 'disabled' : '' %}
    <option {{ optionDisabled }}>
{%- endfor -%}

Does this help you for now?

Copy link

rbrv commented Mar 16, 2020

I understand. We can change to code as you proposed. Thanks for the follow-up!

Copy link

eelke commented May 26, 2020

Ran into the same issue, confirming that the work around does its job for now.

Copy link

NeOMakinG commented Jun 17, 2020

Trying to implement it inside the PrestaShop repository for our twig files, since we've a bunch of stuff already done, we can't use a workaround like setting the var before :/

Copy link

spoeken commented Sep 25, 2020

What would it take to fix this?

Copy link

Khartir commented Oct 5, 2020

@twbartel Is there an issue open for this in the parser project? I looked for one and couldn't find it. Did I miss it or has no issue been opened yet?

Copy link

rubas commented Feb 10, 2021

@twbartel Do you have any update on this? This makes porting an existing code base over pretty annoying ...

Copy link

rubas commented Feb 11, 2021

The ternary operator works.

<li class="page-item {{ 'current' in page.class ? ' active' }}">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

7 participants