title: Twig: nested for each
body: <p>Edit:</p>
  <p>Maybe I need to clarify my problem - I'll leave the original question below.</p>
  <p>How can I properly nest the second for each so that the variable is used as a parameter within the second &quot;view&quot;?</p>
  <p>The variable is set to string values e.g. &quot;BAM2203&quot;. There is no key.</p>
  <p>I'll attach the current output as a screenshot to clarify what I am trying to achieve.</p>
  <pre><code>[msdyncrm_twig]
  {% view entity=&quot;ud_tutorial&quot; name=&quot;View&quot; %}
  &lt;table&gt;
     &lt;thead&gt;
        &lt;tr&gt;
           &lt;th&gt;Kurs&lt;/th&gt;
           &lt;th&gt;Test Variable&lt;/th&gt;
           &lt;th&gt;View with var as parameter&lt;/th&gt;
        &lt;/tr&gt;
     &lt;/thead&gt;
     &lt;tbody&gt;
        {% set seminar_var = null %}
        {% for recordId, record in entityview.rows %}
        {% set seminar_var = record.ud_name %}
        &lt;tr&gt;
           &lt;td&gt;{{ record[&quot;ud_name&quot;].value}}&lt;/td&gt;
           &lt;td&gt;{{ seminar_var.value }}&lt;/td&gt;
           &lt;td&gt;
              {% for seminar_var in seminar_var.value %}
              {% view entity=&quot;ud_submodule&quot; name=&quot;SecondView&quot; parameters=[ &quot;{{ seminar_var.value }}&quot; ] %}
              {% endview %}
              {% endfor %}  
           &lt;/td&gt;
        &lt;/tr&gt;
        {% endfor %}
     &lt;/tbody&gt;
  &lt;/table&gt;
  {% endview %}
  [/msdyncrm_twig]
  </code></pre>
  <h2><a href="https://i.stack.imgur.com/YulUj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YulUj.png" alt="enter image description here" /></a></h2>
  <p>I am using a WP-plugin called Dynamics 365 Integration which can display FetchXML queries and views defined in Dynamics, however I believe my question / problem is related to how I use twig.</p>
  <p>What I am trying to achieve is to set a variable (seminar_var) based on the records returned from one view/fetch (MY_VIEW_1) and to then use that variable to get related records from another view/fetch (My_View_2).</p>
  <p>Right now I have those two working separately, but I fail at combining it.</p>
  <p>This returns all records that I need and for each record the variable is set to the correct attribute (ud_name). An example of a correct value would be &quot;BAM2203&quot;.</p>
  <pre><code>{% set seminar_var = null %}
  {% view entity=&quot;ud_tutorial&quot; name=&quot;MY_VIEW_1&quot; %}
  {% for recordId, record in entityview.rows %}
  {% set seminar_var =  record.ud_name  %}
  
  &lt;table&gt;
  &lt;tbody&gt;
  &lt;tr&gt;
  &lt;td&gt; {{ seminar_var.value }}&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  <p>If I use the beforementioned correct value &quot;BAM2203&quot; as a parameter for the following view, I also get the desired records.</p>
  <pre><code>{% view entity=&quot;ud_submodule&quot; name=&quot;My_View_2&quot; parameters=[ &quot;BAM2203&quot; ] %}
  </code></pre>
  <p>However, combining these two returns &quot;No record found&quot;:</p>
  <pre><code>{% set seminar_var = null %}
  {% view entity=&quot;ud_tutorial&quot; name=&quot;MY_VIEW_1&quot; %}
  {% for recordId, record in entityview.rows %}
  {% set seminar_var =  record.ud_name  %}
  
  &lt;table&gt;
  &lt;tbody&gt;
  &lt;tr&gt;
  &lt;td&gt; {% view entity=&quot;ud_submodule&quot; name=&quot;My_View_2&quot; parameters=[ &quot;{{ seminar_var.value }}&quot; ] %}&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  <p>To me it seems like I cannot access the data stored in the variable from within the nested view, as the nested view does work, if I hardcode the parameter.</p>
  <p>Maybe someone has an idea on how to do this or could point me in the right direction with regard to the twig documentation.</p>
  <p>Best</p>