0

Is it possible to display the list of the first child of every book with a view? I couldn't figure that out so I added boolean to the book content type to check which child is the first child. If that's not possible I'll just keep it the way it is, but the main problem is overwriting the the name of the first chapter (keep the url) with the name of the book. I wanted to do that with the custom text field, but I don't see the replacement pattern of the book name, so is that even possible?

I'm using Drupal 8.

Thanks in advance!

drupal view

drupal view

1

It's not at all a problem to override the link text with another field. Title field settings have the Rewrite results with the Override the output of this field with custom text, with available tokens listed below that under Replacement patterns.

  1. To get the top level Book information add the Relationship Top Level Book.
  2. Edit the Title Field and make sure it uses the Relationship, this will display the main Book title for each of the book Pages in the results, instead of the Pages titles. (I'm assuming you've created the Content Views showing Book pages.)
  3. Edit the field settings to Exclude from display and untick Link to the Content while keeping the Formatter Plain text, so the main book link doesn't interfere with overriding.
  4. Add Field Link to Content, configure it under Rewrite results with Override the output of this field with custom text, Output this field as a custom link, enter token for your title field into the Text field, something like {{ title }}

Now you have links for each Views result that link to Book Pages but the link text is the main Book title.

Book pages weight

The real problem is showing only the first Book pages. Weight is available as a Field within Views, so you can show and sort the book pages in the results according to their set order. Lowest numbers float to top, large numbers fall to the bottom, as is always the logic with weight in Drupal.

But there doesn't seem to be a Filter available for the Weight, at least I'm not seeing any right now, so it doesn't seem possible to filter out only the first child page of every Book.

It is possible to work around it by creating a separate Views Display for each Book you have in Drupal. Set Sort criteria to Book Weight, and Pager to only show 1 result. This way only the first Book page will be shown, but you'll have a separate Block for each Book to show this.

If you have more than one level of the book pages use the Filter Depth with the value 2. (1 depth is the main Book page and 0 is for book pages that don't belong to any Book.)

You can make it look like it's the same Block with some styling after you display all those Blocks in the same theme region.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.