Answers.Body: <p>Please try the following code:</p>
  
  <pre><code>{% set dynamicMenu = menutype~".menuGlobal" %}
  
  {% for block in dynamicMenu %}
  .
  .
  .
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-20T15:09:11.840Z
Answers.LastActivityDate: 2017-12-20T15:09:11.840Z
Answers.UserDisplayName: hashtagerrors
Answers.Body: <p>I believe you're looking for Twig's <a href="https://twig.symfony.com/doc/2.x/functions/attribute.html" rel="nofollow noreferrer">attribute</a> method.</p>
  
  <pre><code>{% for block in attribute(menutype, menuGlobal) %}
  </code></pre>
  
  <p>It allows you to get dynamic attributes off of a variable.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-20T19:33:47.887Z
Answers.LastActivityDate: 2017-12-20T19:33:47.887Z
Answers.UserDisplayName: Brad Bell
Body: <pre><code>the var menutype is set to {{ menutype }}
  
  {% for block in menutype.menuGlobal %}
  </code></pre>
  
  <p>I'm trying to pass the result of {{ menutype }} into the for loop to return a dynamic menu, but the loop doesn't run. Hardcoding the string works, so the loop is fine, just appears not to recognise the variable output in the for statement.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-20T13:50:49.043Z
Comments.Text: What is the data you have assigned to {{ menutype }}? Is it a Navee object? Is it a custom field? Is it a structure? Give a bit more info here on what that data is and i'll be able to help. Also, do you have devmode on?
Comments.UserDisplayName: John
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-12-21T15:05:05.647Z
Comments.Text: Could you post more of your code? What does the variable `menutype` look like? Does it have `menuGlobal` as a child in it?
Comments.UserDisplayName: Cavell Blood
Tags: <templating>
Title: Use twig Var in for loop
ThreadText: # Use twig Var in for loop
  
  (Asked by: username_0 on 2017-12-20)
  
  ```
  the var menutype is set to {{ menutype }}
  
  {% for block in menutype.menuGlobal %}
  
  ```
  
  I'm trying to pass the result of {{ menutype }} into the for loop to return a dynamic menu, but the loop doesn't run. Hardcoding the string works, so the loop is fine, just appears not to recognise the variable output in the for statement.
  
  **Tags:** templating
  
  > **Comments:**
  > **username_1**: What is the data you have assigned to {{ menutype }}? Is it a Navee object? Is it a custom field? Is it a structure? Give a bit more info here on what that data is and i'll be able to help. Also, do you have devmode on?  
  > **username_2**: Could you post more of your code? What does the variable `menutype` look like? Does it have `menuGlobal` as a child in it?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2017-12-20. Score: 1
  
  Please try the following code:
  
  ```
  {% set dynamicMenu = menutype~".menuGlobal" %}
  
  {% for block in dynamicMenu %}
  .
  .
  .
  {% endfor %}
  
  ```
  
  
  ---
  
  ### Answer by username_4 on 2017-12-20. Score: 0
  
  I believe you're looking for Twig's [attribute](https://twig.symfony.com/doc/2.x/functions/attribute.html) method.
  
  ```
  {% for block in attribute(menutype, menuGlobal) %}
  
  ```
  
  It allows you to get dynamic attributes off of a variable.
  
  
  ---
  
  