How do I call a page.html.twig template variable from the book-tree.html.twig template.
Using kint, I have found the variable, nid as in the screenshot below:
The 'nid' is highlighted, but it is the 'x-default value that is required.
This variable will be used in a set statement, comparing it to the item.original_link.nid to set an active class.
This page nid is not available within the book-tree.html.twig template.
As per Answer 1, I have created a _preprocess
function in my subthemes .theme file as below:
function subtheme_bs_preprocess_book_tree(&$variables) {
$variables['page_nid'] = 'Add code to get the node id variable';
}
The variable page_nid
now shows up in the book-tree.html.twig
array. The result is 'page_id' => string(36) "Add code to get the node id variable"
which is the static text I added.
I would like help on how to call the nid
value from the node.html.twig
template. I have tried several combinations:
$variables['page_id'] = $variables['page']['content']['book_navigation']['#book_link']['nid']
But this and many other compinations I have tried all end with a:
Notice: Undefined index: page in subtheme_bs_preprocess_book_tree()
Maybe I need to call an Available method
but have no clue as to how this is done.
Below is a screenshot of the {{ kint() }}
output from the top of the node.html.twig
file.
the value I need to target is the 115 in this line 'x-default' => value (3) 115.
Many thanks in advance.