1

I'm a newbie at using Neo and am finding it hard to get the concept correct for nesting and retrieving child elements.

I have been trying to retrieve them by creating element queries, but I am unable to find them.

My Neo set up is:

  1. Add a nav item - which you can title (plainText)
  2. add a drop down (this is a empty NEO block type to trigger the code to add a <ul>)
  3. add a (or multiple) entry to that drop down (to create the <li>)

enter image description here

EDIT: I have added the Neo fields as well:

enter image description here

enter image description here

enter image description here

I guess this would be a good point to ask, is this to many level down already?

When fully input the layout looks like this:

enter image description here

To try and render this code I have used for loops but I am missing something about to get the elements inside of the drop down matrix (so any help here would be great).

{# Neo container #}
{% set navItems = navigation.navigationMatrix.level(1).all() %}

{# Top level  #}
{% for block in navItems %}

  <li class="nav-link heading> {{ block.plainText }}

    {# Cycle over dropDown as its the only child #}
    {% for child in block.children %}
      
      {# Could use a switch - but there is only one right now #}
      {% if child.type.handle == 'dropDown' %}

        {# Create the drop down #}
        <ul class="dropdown">

          {# ERROR - cannot get the entry inside - this is where I need help #}
          {% set entries = child.entry.all() %}

          {% for entry in entries %}
            <li>{{ entry.title }}</li>
          {% endfor %}
          
        </ul>

      {% endif %}

    {% endfor %}
  </li>
{% endfor %}

Any help on this would be great - I have a feeling that i have missed some core concept in the structure NEO. The original NEO component I had designed was more complicated than this, but I decided to dull it back to make it work, but to my shame have failed at making the simple version work.

If you have any questions or need more information then please let me know.

W

2
  • Are you sure the type is 'dropDown'? Does it work if you remove the check ({% if child.type.handle == 'dropDown' %}? At first sight, it looks fine (without being able to see all field handles'. Jul 4, 2022 at 20:32
  • @MaxStrebel - Thanks for the reply: I've added some new screen shots, hope that is help. It works up until I try and get the Entry. What I've found to be an issue if running for loops and setting variables to what I believed would be an array.
    – Wally
    Jul 4, 2022 at 21:21

1 Answer 1

1

According to the screenshots, you have 2 nesting levels. I guess you can solve this by querying for children a second time.

But I'd like to propose a simpler solution. Keep the code like it is, but allow multiple dropdowns in NEO and add the entry field to the dropdown element.

This way you save one nesting level and have the same result.


If you want to keep NEO like it is, you'll need to query the children again.

{# Neo container #}
{% set navItems = navigation.navigationMatrix.level(1).all() %}

{# Top level  #}
{% for block in navItems %}

  <li class="nav-link heading> {{ block.plainText }}

    {# Cycle over dropDown as its the only child #}
    {% for child in block.children %}
      
      {# Could use a switch - but there is only one right now #}
      {% if child.type.handle == 'dropDown' %}

        {# Create the drop down #}
        <ul class="dropdown">

          {# This is wehere you need to get NEO children first #}
          {% set dropdownEntries = child.children %}

          {% for dropdownEntry in dropdownEntries %}
            <li>{{ dropdownEntry.entry.title }}</li>
          {% endfor %}
          
        </ul>

      {% endif %}

    {% endfor %}
  </li>
{% endfor %}

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.