Unpredictable URL encoding

You cannot nest the curly braces. Instead use printf + safeHTML I.e. do something like:

{{ printf `<img src="%s" alt="%s" … other stuff />` $var_holding_src $var_holding_alt | safeHTML }}