I know this is really old, but I think it is close to what I need for something I’m working on. See:
Indirectly indexing through extruder objects - General Discussion - Klipper
It makes sense somewhat (I’m still a novice) that what I was trying to do is different from how you can do macros because this involves paths. It looks like this could be what I need to build the path, but I think the last piece I need to figure out is how do I capture the value that the path references.
So say I had something like below. What would I put where the ???s are to pull the value that the ns.path|join references? i.e. the value of printer.extruder1.temperature
[gcode_macro test]
variable_temp: 0
variable_ext: "extruder1"
gcode:
{% set ns = namespace() %}
{% set ns.path = ['printer.', ext, 'temperature'] %}
SET_GCODE_VARIABLE MACRO=test VARIABLE=temp VALUE=???