I am trying to pass a variable to a macro in jinja but every time I try to do that I get an error message saying
jinja2.exceptions.TemplateSyntaxError: unexpected '}', expected ')'
Here is my code:
{{ my_macro(value='{{var1}} - {{var2}}') }}
Its documented in Jinja documentation that when using a variable within a double bracket literal {{ }} then the variable does not need an additional double bracket for it and Jinja would resolve it correctly. However, when the variable is within a quote literal, the variable does not seem to resolve to its value and rather it name would be passed as a string which is not right.
{{ my_macro(value='var1 - var2') }}
This would make value equal to a string without resolving var1 and var2 to their values. There should be a way to use a variable inside a quite literal which is within an outer double bracket. A possible scenario where this happens is when a macro with a parameter is called and a value of the argument is a variable.
I have solved this by using the join function to an array as shown in the code below.
{{ my_macro(value=[var1,' - ',var2]|join) }}