Q: I'm using the Book module to maintain the parent-child relationship between content. I want to see all child pages expanded when I see a parent node details page. How can I achieve it?
I tried with THEMENAME_preprocess_book_tree(), but so far I have not been able to achieve that I wanted.
Is this the right hook to use in my case?
A: I managed to find a solution. I would like to post it here if somebody looking for similar solutions.
Make a view for the parent page with all needed configurations. In my case, I have the main chapter page as the parent, the content type is 'chapter'. And when I see the view in a page I want to see all sub-chapters coming under it. The further steps are followed:
I tried with THEMENAME_preprocess_book_tree(), but so far I have not been able to achieve that I wanted.
Is this the right hook to use in my case?
A: I managed to find a solution. I would like to post it here if somebody looking for similar solutions.
Make a view for the parent page with all needed configurations. In my case, I have the main chapter page as the parent, the content type is 'chapter'. And when I see the view in a page I want to see all sub-chapters coming under it. The further steps are followed:
- Browse to /admin/structure/views and click on "Add view".
- Enter a view name, Select content type from view settings
- Check the "Create a block" checkbox only. Then click on "Save & edit".
- On the right-hand side, click on "Advanced" so that the advanced menu appears.
- Click on "add" next to "Relationships" to add a relationship.
- Select "1st parent" (the parent book node) and click on "Apply and configure relationships".
- Check the "Require this relationship" checkbox and click on "Apply".
- Click on "add" next to "Contextual filters" to add a contextual filter.
- Select "ID" (The node ID) and click on "Add and configure contextual filters". Choose relationship to "Book 1st Parent"
- In the "when the filter value is not available" section, select "Provide default value" and in the "Type" drop-down menu, select "Content ID from URL"
- click on "Apply" & Save the view
- Place the just created block in the page by visiting structure > block layout
No comments:
Post a Comment