When I started learning klipper and writing my own macros, I was very surprised that valid jinja code does not work for initializing variables (I think wrapping them in {} did not help either).
By looking at the implementation, I found out that the initialization expression are parsed as a python ast, which is why you have to write True instead of true.
What is it that you are expecting that macro to do? As written, this macro has no function except to issue the M117 command with no arguments, which simply clears the display from whatever message was last displayed with the M117 command (if any). The macro defines a variable but never uses it, so the variable is unnecessary and can simply be deleted, unless you intend for it to be used by some other macro.
I am not searching for solutions, I already know about them. I want to report an issue that is caused by a lack of documentation/bad design decisions.
What the macro does is not important. My problem is that nothing mentions that whatever you write as the default value for the variable must be a valid python literal.
When you paste the macro into klipper, you get:
Option ‘variable_example’ in section ‘gcode_macro EXAMPLE’ is not a valid literal: malformed node or string on line 1: <ast.Name object at 0xffffad6d5ba0>
This is because in python, you write True, instead of true. In Jinja, you can write not only True, but true as well. So one might think that one could write jinja code as the default expression (which is not the case).
I see. You do have a point there. Klipper does use a modified jinja2 implementation. Some built-in jinja2 filters simply don’t exist in Klipper’s implementation, and some of the formatting conventions are different (simpler) too. For me, it took some trial-and-error and experimentation to figure out how to do what I wanted to do.