var() above doesn’t return any value, though in least complex cases it works well. It seems that I don’t quite understand the sequence of operations performed when calculating ternary operators. Or it’s just a syntax mistake…
It worked, although there is one unpleasant side effect: formatting a singlequoted multi-line is not particularly supported in built-in IDE (I tried YAML “>” symbol). However, this is not significant.
For the record: There is no requirement to put the ternary expression into quotes. The quotes around the expression are one way to satisfy the YAML format issue that :[space] outside of a string is always interpreted as a key-value definition and so cannot follow on the same line as another key-value definition. So,
yamlkey: =test ? ifTrue : ifFalse
will always result in an error because the parser gets confused by the :[space] in the ternary expression. If you put the entire expression inside "..." then the parser knows it is a string and doesn’t make the key-value mistake.
Any other option that removes the space after the colon in the expression will also fix the issue. For readability, my preference is just (...) around each section: