Pass additional variable into existing twig template (Book module)
Drupal offers preprocess functions where additional variables for templates can be set up.

The naming convention is THEMENAME_preprocess_THEMEHOOK(). In your case, you want to add a variable for book-tree.html.twig. The machine name for this is the first part of the template, with underscores replacing hyphens. In this case it would be book_tree. So your function would be THEMENAME_preprocess_book_tree().

Preprocessors receive a single argument, an array. The keys of this array become the variables available in your twig template.

THEMENAME_preprocess_book_tree(&amp;$vars) {
  $vars['book_author'] = some_function_that_gets_the_author();
}


Now the variable book_author will be available to your template.