4 ms·
Wait, how is this any cleaner/better than a ternary statement? Beyond that the initial ugliness comes from using conditional markup in the first place. The only
by shaunxcode 17y ago
Wait, how is this any cleaner/better than a ternary statement? Beyond that the initial ugliness comes from using conditional markup in the first place. The only thing that is going to fix that is abstracting yourself from markup entirely.
- dugmartin 17y agoConceptually its the same as a ternary statement with the addition that the output is looped over if the expression evaluates to an array. Conditional markup is necessary somewhere in the system - this puts it in the templates in more compact form that won't break like the multi-line block in the example. If you put the markup in the controller then you blur the line in the MVC architecture.
- shaunxcode 17y agoOk, the syntax does not exactly lend itself to clarity. If you're going to be parsing why not add key:value pairs so you don't have to use the back tick? Something like: {@ users ? before: "<div id='users'>Users<ol>" each: "<li>{fullname}</li>" after: "</ol></div>" else: "No users found" @}