Pass a variable array to a macro I try to pass a variable from to a macro:

{% set syName = {
   x: { name: "Schön"},
   y: { name: "Leicht bewölkt"},
   z: { name: "Stark Bewölkt"},
    } 
%}

{% macro prognose(symbol, syName) %}
   &lt;img src="test/{{ symbol }}.png"&gt;
   {% for alt in syName %}
      {{ alt.name }}
   {% endfor %}
{% endmacro %}

{{ _self.prognose(  '1' , syName ) }}


So far so good. But this passes all the content from the variable into the macro. I want to trigger x, y, z individually.

So I tried to write it like this: {{ _self.prognose(  '1' , syName.x ) }}

This gives the error: 


  Impossible to access an attribute ("name") on a string variable
  ("Schön")


How do I have to write this?
The first example makes sense because you are passing a multidimensional  array (syName), looping through that array, assigns each array within to alt allowing you to then access the values through dot notation ({{ alt.name }}), because alt is an array.

In your second example you are passing through just one array, so when you loop through it, the value in name is assigned to alt as a string. (the value in the array) so you can echo it out just by doing {{ alt }}

So your code could look like:

{% macro prognose(symbol, syName) %}
   &lt;img src="test/{{ symbol }}.png"&gt;
   {% for name in syName %}
      {{ name }}
   {% endfor %}
{% endmacro %}

{{ _self.prognose(  '1' , syName.x ) }}


This will output Schön

To make things even easier for yourself, if you are passing just one array i.e syName.x You don't even need the loop as you can just access the value through dot notation:

{% set syName = {
   x: { name: "Schön"},
   y: { name: "Leicht bewölkt"},
   z: { name: "Stark Bewölkt"},
}%}

{% macro prognose(symbol, syName) %}
    &lt;img src="test/{{ symbol }}.png"&gt;
    {{ syName.name }} 
{% endmacro %}

{{ _self.prognose('1', syName.x) }}


This will output Schön