I’m working on a site right now and I’m trying to do basic pattern matching on data values without resorting to a mess of if/else statements. Basically, I’m creating a “Feature support” table on the basis of YAML data where some features are 100% supported, some are not supported, and some are partially supported. I want to have different emojis associated with each of these three options. Here’s some example YAML:
Also, that won’t work. The $foo variables defined within if block live only within those blocks… You won’t be able to access $emoji in your example outside of that if .. end.
The working form of that nature would need to use $.Scratch.Set instead.
@kaushalmodi I was hoping to avoid using cond as well but on second thought, I probably shouldn’t expect something more concise from Go templates. I think your proposed solution is as elegant as it’s gonna get Thanks!