Passing/updating variables between macros

So, I can rewrite your MAIN as:

[gcode_macro MAIN]
variable_temp2: 0
gcode:
    _MINOR
    M118 0 - Temperature is 0 C.
    G4 P1000
    _MINOR
    M118 1 - Temperature is 0 C.
    G4 P1000
    _MINOR
    M118 2 - Temperature is 0 C.
    G4 P1000
    _MINOR
    M118 3 - Temperature is 0 C.
    G4 P1000
  M118 End of test.

(It evaluates as a template to the text upon call, and then this text will be executed, so it can’t show any changes inside the template).
(Any updates will be shown in the next call to MAIN).

The next idea would sound like: “I can do a loop by the recursion!”

[gcode_macro _MINOR]
variable_temp1: 0
gcode:
  {% set COUNT = params.COUNT|default(0)|int %}
  {% set temp1 = printer.extruder.temperature | float %}         # read live extruder temperature
  M118 _Minor Call {temp1} C.                                    # Echo temp to show what macro has what value
  SET_GCODE_VARIABLE MACRO=MAIN VARIABLE=temp2 VALUE={temp1}     # Update temp2 in macro MAIN
{% if COUNT < 10 %}
  MAIN COUNT={COUNT}
{% endif %}

[gcode_macro MAIN]
variable_temp2: 0
gcode:
    {% set COUNT = params.COUNT|default(0)|int %}
    _MINOR COUNT={COUNT + 1}
    M118 {count} - Temperature is {temp2} C.                     # Echo temp in console
    G4 P1000                                                     # Wait 1 second
  M118 End of test.

Alas, it is also invalid, because Klipper forbids recursions.

So, the closest that you can get Jinja2 + G-code is to define 10 macros and call them conditionally, I guess.

Hope that explains something,
-Timofey