The book module is written to see if there are any children of the current page, and if so print out a list of links to the child pages in a sort of navigation menu with a top border on it's enclosing DIV.

I would very much like to precede that list with something like:

<div class="booknavtitle">Subsections</div>

... inside the navigation DIV itself, so it falls within that top border on the Book navigation DIV.

I've been poking around at the innards of the book module. I haven't however been able to figure out where to insert the code to do this.

I would be very greatful if someone could steer my attention to the right spot.

Thanks for reading.

Comments

Bill Bostick’s picture

Copy the file book-navigation.tpl.php from the book module folder to your theme folder, and then edit this copy to include the markup you want. Then flush the theme cache.

ss_drupal’s picture

Thanks, but actually that can't work.

The relevant lines in that file say:

<?php if ($tree || $has_links): ?>
  <div id="book-navigation-<?php print $book_id; ?>" class="book-navigation">
    <?php print $tree; ?>
    ... etc

So using that with this example:

<?php if ($tree || $has_links): ?>
  <div id="book-navigation-<?php print $book_id; ?>" class="book-navigation">
    AAAAA<?php print $tree; ?>BBBBB
    ... etc

AAAAA would print above the navigation DiV, and above the enclosing upper border.
BBBBB would print below the navigation links.

I think I need to find the place where $tree is converted into HTML -- where the actual DIV tag is generated in order to get between the opening DIV tag and the opening UL for the list.

Thanks again.

Bill Bostick’s picture

So the AAAAA prints BEFORE the navigation DIV generated by the line ABOVE it in the template file? I'm pretty sure that's not how it works. But if the javascript thing works for you... cool.

ss_drupal’s picture

I tested it myself before posting this whole subject.

It seemed the natural way to go.

Easy to test if you want to verify.

ss_drupal’s picture

The only practical way to make this happen is to add a list item to the beginning of the list with javascript.

I did it from drupal.js using jquery.

You can then style your addition from your regular theme css.

freeform.steph’s picture

Sillyness! - adding javascript is going way over the top. Using Firebug in Firefox will shown you that the line is applied to ul, not a containing div, and that is why added text appears above the line.

Comment 3180164 was correct. Copy book-navigation.tpl.php to your theme and adjust as needed.

There are many variables available, listed in the file, so you have many customization options. Here's an example that displays a title above the list for a specific book and only on the parent page:

Above the "print $tree" line:

<?php
   if (($book_id == 7) && ($current_depth == 1)) {
	print "<div class='book-nav-title'>" . t("my navigation title") . "</div>";\
   }
?>

To 'fix' the text appearing above the line, add the following to your theme's css file:

.book-navigation .menu {
    border-top: 0;
}

.book-navigation {
    border-top: 1px solid #888888;
}