(alternatively ‘@else’ could work maybe without commonId and would take into account all '@if’s)
Technically, i think one could archive this by caching the result of each ‘@if’ evaluation by path in the runtime - or better caching the result if the ‘@if’ has an ‘@else’ key nearby - or the Fusion AST will list in a first level path ‘__else’ all used ‘@else’ keys with their commonParrentPath and commonId so that on occurrence of an ‘@if’ it could be easily checked if its a standalone if or if there is a matching ‘@else’ key and cache it.
On the occurrence of the ‘@else’ one would look in the cache the correct ‘@if’ by path and then render accordingly.
Not a fan because of hte required coupling. Also in programming I like to follow this: Don’t use ‘else {}’. let’s use something ‘else instead | by Georges Jamous | Medium
(more articles about it exist, just randomly picked one)
and I find it makes sense to apply this thought process here too. Above could easily be solved by the fusion Case object, alternatively the tagName could be a ternary EEL expression deciding between H1 and H2. So I don’t even see a sensible use case (well for AFX maybe but that needs to stick to the rules outlined by Fusion)
This is either equivalent to e negation expression via @if which is syntax sugar. @ifNot would be a better name for that but i doubt the advantage justifies the effort.
If the @else would affect a sibling path to the @if statement it would entangle the rendering of those fusion pathes which breaks the partial evaluation fusion usually allows.
I don’t agree with @christianm on the argument in the link, because in fusion there is no execution flow… but I agree, that Case would be better here and makes the fusion code more readable.
With the case element you see at first sight, that this is a decision point (like an if() statement) but when the @if is hidden in the option, it’s not that clear.
I do like that idea, probably would think hard about the naming and if it should be in the fusion package but the idea to make that pre configured seems sensible yeah!
Yes, probably there is a better name for is, I didn’t think too hard about it yet. I just thought Neos.Fusion:Default is too generic…
But where would you place it , when not in the fusion package? It’s not Neos CMS specific, it is useful whenever you use Fusion. (I recently started to use Fusion templates for pure Flow packages and I like it.)
When i thought about @else i was only thinking about AFX part and not really how that would affect how Fusion should be written. And i do agree that @else doesnt make sense in plain Fusion as it will be hard to keep track.
Thanks @christianm for the thing about using else - i never really thought about it but it does increase readability if you can remove some of the elses
But i do think in fusion one need to rely on some kind of else, whether eel ternary or a fusion case, as i cannot controll the flow of the code with an early return… (as you pointed out @till.kleisli )
Note: The suggested afx syntax would also require a fallback from renderer to content in the Matcher implementation. We do this already for Map and Loop where we have a fallback from itemRenderer to content so this may make sense.