1
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.

2
  • 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
    Commented Dec 20, 2017 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? Commented Dec 21, 2017 at 15:05

2 Answers 2

1

Please try the following code:

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

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

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 and acknowledge you have read our privacy policy.

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