In my theme's .theme file I have the book navigation block stored in a twig variable like so.
function mytheme_preprocess_page(&$variables){
$book = \Drupal\block\Entity\Block::load('booknavigation');
$variables['book'] = \Drupal::entityTypeManager()
->getViewBuilder('block')
->view($book);
}
I'm then calling it in my page.html.twig template like so
<div class="sidebar">
{{ book }}
</div>
<div class="content">
{{ page.content }}
</div>
However on basic pages that are book pages, sibling book items are shown but the top level book page is not. Even when visiting the top level book page the link is not shown in the book block.
Why isn't the top level of the book ever displayed? And is there a way I can get the top level to be shown?
UPDATE: I've looked at creating a book-tree.html.twig. The contents are below
{% import _self as book_tree %}
{#
We call a macro which calls itself to render the full tree.
@see http://twig.sensiolabs.org/doc/tags/macro.html
#}
{{ book_tree.book_links(items, attributes, 0) }}
{% macro book_links(items, attributes, menu_level) %}
{% import _self as book_tree %}
{% if items %}
{% if menu_level == 0 %}
<ul{{ attributes.addClass('menu') }}>
{% else %}
<ul class="menu">
{{ dump(book_tree|keys) }}
{% endif %}
{% for item in items %}
{%
set classes = [
'menu-item',
item.is_expanded ? 'menu-item--expanded',
item.is_collapsed ? 'menu-item--collapsed',
item.in_active_trail ? 'menu-item--active-trail',
]
%}
<li{{ item.attributes.addClass(classes) }}>
{{ link(item.title, item.url) }}
{% if item.below %}
{{ book_tree.book_links(item.below, attributes, menu_level + 1) }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
But I don't see where I can access the top level.
UPDATE: I found a workaround but I'm looking for a solution that does not require that workaround. Users should not have to create an empty page with the same title just to act as the non displayed top level.