Setting up and retrieving hierarchical content

There are two different approaches to configuring a hierarchical relationship between two documents.

1. Add the children to the parent document

Content modeling

You can make it easy for editors to define child pages for a given entry. Modify the parent custom type:

This will allow you to add all the children's documents you need for a given parent.

Retrieving the child pages

You can use the fetchLinks query option to grab the necessary fields to build the menu.

Alternatively, you can take the group of links and create an array of the documents UID. With this array of UIDs, you can query all the child documents.

2. Add the parent to the child document

Content modeling

To give a Child document a single parent, modify the child custom type:

  • Add a single Content Relationship field; this will allow you to specify a "Parent page" for a given child.

To allow a child document to have multiple parents or categories, modify the child custom type:

  • Add a Group field

  • Add a Content Relationship field inside the group

This will allow you to add as many parents or categories.

Retrieving the child pages

Using this method, you would be able to know which parent(s) a child document has and query all the children of a given parent. To retrieve all the child documents for a given parent, query the child documents by their Content Relationship field. Refer to your favorite technology documentation to learn how to query by Content Relationships.