Template Sensor attribute_templates via jinja

I’ll try to get some of the attributes of another sensor for another template sensor. Hereby,
I try to define the attribute_templates of an template sensor via jinja, but constantly receive the message

Invalid config for [sensor.template]: expected a dictionary for dictionary value @ data['sensors']['octoprint_petg']['attribute_templates']. Got '{%- for key, value in states.sensor.octoprint.attributes.spools.PETG.items() -%}{{key}}: {{value}} {% endfor %}'. (See ?, line ?).
    octoprint_petg:
      value_template: '{{ states.sensor.octoprint.attributes.printer.bedTarget }}'
      unit_of_measurement: 'g'
      attribute_templates: >-
        {%- for key, value in states.sensor.octoprint.attributes.spools.PETG.items() -%}{{key}}: {{value}}
        {% endfor %}

When executing the jinja code via the development tools, I get a niceresult:

Blau: 815
Braun: 1000
Schwarz: 1000
Weiß: 1000

What am I doing wrong? Seems to be indentation but I cannot get it working

You can’t template fields. Only field contents.

    octoprint_petg:
      value_template: '{{ states.sensor.octoprint.attributes.printer.bedTarget }}'
      unit_of_measurement: 'g'
      attribute_templates:
        balu: >
          {{ states.sensor.octoprint.attributes.spools.PETG.Blau }}
        ...etc...