Question

Photo of Long Pham

0

Accessing Child Content Channel Items from Parent Channel Item using Lava

I'm trying to get the child content channels within the for loop of parent channels. I'm referencing item.ChildItems doesn't work.

If I do this -

{% for item in Items %}

    {% assign childItem = item.ChildItems | First | Property:'ContentChannelItem' %}

    {% chiIdtem.Id %}

{% endfor %}

The childItem.Id is the ID of the parent channel object, not of any children.

I also tried using item.ChildContentChannelItems but that doesn't work either. 

Are there any documentation about this ? Thanks for viewing !

  • Photo of Daniel Hazelbaker

    0

    In this case, you will want `{% assign childItem = item.ChildItems | First | Property:'ChildContentChannelItem' %}`

    The "ChildItems" and "ParentItems", despite the names, don't actually point to the items but to a "helper" object that has the parent (ContentChannelItem) and the child (ChildContentChannelItem).

    If you want to loop over all the child items I think you can do:

    {% assign childItems = item.ChildItems | Select:'ChildContentChannelItem' %}
    {% for child in childItems %}
        ...
    {% endfor %}

  • Photo of Long Pham

    0

    Got it, I was close !  :)  Thanks, Daniel.