1

I'm trying to use drupal_block("book_navigation") in a twig template (with the twig_tweak module installed) to display a list of chapters for a book page. But I'm getting a list of all books and their chapters.

Is there a way to use drupal_block("book_navigation") to produce a list of chapters for just the one book, maybe by passing the id of the book node as a second parameter? Or some other way?

Compare to the user interface /admin/structure/block. There, when you place a Book Navigation block in a region, you can choose the configuration option "Show block only on book pages". This causes the block to produce a list of chapters for only the book whose page the list appears on. So it's clearly possible to do it using the book navigation block. Just need to know how.

1

After digging into the Book module code, I discovered that in a twig template (with the twig_tweak module installed) I can use

    {{ drupal_block("book_navigation", {block_mode: "book pages"}) }}

to create a list of chapters for only the current book (which is what I need). This is equivalent to the configuration option "Show block only on book pages". Probably in documentation somewhere, but much googling didn't find it for me.

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.