Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Children Array empty #412

Open
DavidKabelitz opened this issue Jan 13, 2025 · 6 comments
Open

Children Array empty #412

DavidKabelitz opened this issue Jan 13, 2025 · 6 comments

Comments

@DavidKabelitz
Copy link

Describe the bug

Hi,
some navigations of existing projects are broken. Not sure for how long tbh.

Nodes query:

{% set nodesMain = craft.navigation.nodes()
.handle('mainMenu')
.with(['children'])
.level(1)
.all() %}

{% nav node in nodesMain %}
{% if node.children |length %}

{% endif %}
{% endnav %}

Either in a nav or for loop the childs are not rendered and the childs array is empty.

Childs are rendered when we use:

{% ifchildren %}

    {% children %}
{% endifchildren %}

But we need a custom part for the childs

Steps to reproduce

Craft CMS version

4.13.7

Plugin version

2.1.1

Multi-site?

No response

Additional context

No response

@engram-design
Copy link
Member

I don't see any issue on my end I'm afraid, altering your template slightly:

{% set nodesMain = craft.navigation.nodes()
    .handle('mainMenu')
    .with(['children'])
    .level(1)
    .all() %}

{% nav node in nodesMain %}
    - {{ node.url }}<br>

    {% for subNode in node.children %}
        -- {{ subNode.url }}<br>
    {% endfor %}
{% endnav %}

Produces a correct hierarchy for me:

- https://craft4.test/page-1
-- https://craft4.test/another-page
-- https://craft4.test/test-page
- https://craft4.test/page-2
-- https://craft4.test/some-items

Can you share a screenshot of your navigation node builder, in case that's a factor? Does it work without eager-loading the children

@DavidKabelitz
Copy link
Author

@engram-design Hi Josh,
we had it the same way like your answer. The if statement it just used to show icons and class names at the parent node.

And yes without eager loading everything is back.

@engram-design
Copy link
Member

What sort of nodes are they in your navigation? Entries, custom or other? I don't think it'll make a difference, but just checking.

@DavidKabelitz
Copy link
Author

Mix of Categories, Entries and some custom

@DavidKabelitz
Copy link
Author

@engram-design Hi Josh, how do we continue with that one here?

@engram-design
Copy link
Member

I'm still not able to replicate this behaviour, sorry. I'm not sure how eager-loading could omit the child nodes from the structure output either.

If you're up for sending your database to [email protected] we can take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants