Drupal: create a view block of all children of a book page

Creating a view block that contains all children of a certain book page is not that difficult. Suppose we have the following book hierarchy:

  • Book title
    • Chapter 1
      • Section 1.1
      • Section 1.2
    • Chapter 2
      • Section 2.1
      • Section 2.2
We will show how to create a block that will show the relevant section pages on the "Chapter 1" and "Chapter 2" pages.

  1. Browse to /admin/structure/views and click on "Add new view".
  2. Enter a view name, uncheck the "Create a page" checkbox and check the "Create a block" checkbox. Then click on "Continue & edit".
  3. On the right-hand side, click on "Advanced" so that the advanced menu appears.
  4. Click on "add" next to "Relationships" to add a relationship.
  5. Select "Book: Parent" (the parent book node) and click on "Apply (all displays)".
  6. In the "Configure Relationship: Book: Parent" screen, check the "Require this relationship" checkbox and click on "Apply (all displays)".
  7. Click on "add" next to "Contextual filters" to add a contextual filter.
  8. Select "Content: Nid" (The node ID) and click on "Apply (all displays)".
  9. In the "Configure contextual filter: Content: Nid" screen, 
    1. change the relationship to "Book Parent"
    2. in the "when the filter value is not available" section, select "Provide default value" and in the "Type" dropdown menu, select "Content ID from URL"
    3. click on "Apply (all displays)"
  10. Remember to click the "Save" button on the top-right to save your view.
You have now created a block that will show the children of a certain book page. To add the block to a certain page, browse to "/admin/structure/block" and configure the block.

Tags: 

Share