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.

  • 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?
    – John
    Dec 20 '17 at 13:50
  • Could you post more of your code? What does the variable menutype look like? Does it have menuGlobal as a child in it? Dec 21 '17 at 15:05

Please try the following code:

{% set dynamicMenu = menutype~".menuGlobal" %}

{% for block in dynamicMenu %}
{% endfor %}

I believe you're looking for Twig's attribute method.

{% for block in attribute(menutype, menuGlobal) %}

It allows you to get dynamic attributes off of a variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.