Qute: prefix loop metadata
See original GitHub issueDescription
https://quarkus.io/guides/qute-reference#loop_section says that we get iterator metadata index
, hasNext
, odd
and even
, but it does not show any example of how to access it, leading me to believe it would be a property of the iterated variable such as it.index
. I now realise it showed this example:
{#each items}
{count}. {it.name}
{/each}
Which introduces the count
metadata, I guess, but because it’s not properly introduced I assumed it was a random toplevel.
The docs should be more clear as to which metadata properties are available, and also this is terrible wrt scoping, because it will automatically override any explicitely declared binding named count
or index
by surprise.
I do agree it’d be weird to tack these metadata properties to the iterated variable.
In other templates, I’ve seen the iterated variable name being used as a prefix, though, such as it_count
or myVar_hasNext
which greatly limits binding clashes.
Could we get such prefixed properties instead?
Implementation ideas
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (13 by maintainers)
Choosing where to stop with adding syntax sugar is certainly one of the more artistic parts of language design 😃
Please make sure we have a very actionable error message so that people know how to fix it. I’m pretty sure it’s often used, given how often you have to special case the first or last iteration.