(sometimes when programming Hugo templates, I get the feeling that programming languages in the 1990s were more versatile and programmer-friendly than Hugo templates…)
The thing is, I need to assign the result of the cond expression to a variable that is later used across several HTML tags. So what I need is something like that:
The problem now is another quirk of Hugo templates: variables that are assigned inside a block (like with) do not keep their assigned value outside of the block. So the above code would not work. I could use a Scratch, but is that really necessary?
Yes I could extract this into a separate template, but that gets very complicated because of other reasons.
Is there any way I can assign to a variable something that depends on a resource?
Wow okay. So my assumption was wrong, that variables won’t keep their assigned values outside a block. I’m pretty sure I have read that somewhere on this forum, but anyway.