Question

Photo of Long Pham

0

Access parent Content Channel from child item with Lava

Hi,

I'm a newbie to Rock and is experimenting with the power of Lava but is running into a block.

I created 2 Content Channels - Books and Chapters.  The Chapters channel is a child channel to the Books channel. 

I created a page that has a Content Channel View block to display all Chapters.

For each Chapter I'd like to display an image attribute from the parent Books channel of that Chapter.

How would I access the parent Books image attribute using Lava inside the Chapters {% for item in Items %} loop ?  Is this possible ?

Thanks for viewing.


  • Photo of Daniel Hazelbaker

    0

    A content channel item can actually have more than one parent, but assuming you only have one parent item this should get you to the parent item:

    {% assign parent = item.ParentItems | First | Property:'ContentChannelItem' %}

    You can then get to your parent attribute like:

    {{ parent | Attribute:'key' }}

  • Photo of Long Pham

    0

    Awesome, that works !  Thanks Daniel.