Error processing inline-if twig statement
See original GitHub issueGot this error while testing:
Error
[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]
[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 }}
{{
purchasable.salePrice|commerceCurrency(
cart.currency
)
}}
</option>
{%- endfor -%}
</select>
.prettierrc
{
"tabWidth": 4,
"plugins": ["./node_modules/prettier-plugin-twig-melody"],
"twigMultiTags": [
"nav,endnav",
"switch,case,default,endswitch",
"ifchildren,endifchildren",
"cache,endcache"
]
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:8
Top Results From Across the Web
How do I use php inline with a twig template? - Stack Overflow
I found the answer myself. I am using Laravel 5.1, with rcrowe/TwigBridge. I am able to do this: {{ app.request.is('admin/users') ?
Read more >Twig for Template Designers - Documentation - Twig - The ...
This document describes the syntax and semantics of the template engine and will be most useful as reference to those creating Twig templates....
Read more >Valid Twig syntax is incorrectly escaped in Views rewrites
I'd try not to name it after "Twig" or for the purpose of Twig if possible ... but the rewrite field is processed...
Read more >Twig Operators | Branch CMS Documentation
A ternary operator is basically a condensed version of an if/else statement. Long form. If the variable exists, output it. Otherwise, output something...
Read more >Twig: The Basics - SymfonyCasts
Welcome to the world of Twig! Twig is a templating language for PHP, which is a boring way of saying that it's a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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
Does this help you for now?
Update The ternary operator works.
<li class="page-item {{ 'current' in page.class ? ' active' }}">