Hi

I have been searching drupal.org for ways to customise the apperance of the book module's navigation.

What I would like to be able to do is display the tree-view (TOC) links above the content of book pages and keep the prev / up / next links at the bottom (but possible have the option to display them up top too).

So far I have been poking around with theme_book_navigation in book.module and have figured out how to disable certain parts of the book navigation. I know I can totally disable it by using the following function in my theme's template.php file:

/**
* Overrides the presentation of book nodes.
*/
function phptemplate_book_navigation($node) {
return '';
}

But I can't figure out how to get drupal to render book navigation above the content of book pages. I know it must be easy if you know how, but my PHP knowledge is limited.

Any guidance would be appreciated

Drupal 4.7 RC 2
PHP Template
Customised 'Friends Electric' Theme

Cheers
Jay

Comments

coreyp_1’s picture

I don't have time to write any code right now, but perhaps this suggestion could get you started:

You could write a custom module to add the book navigation block into the body of the node.

hook_nodeapi() is called when any node is viewed, and allows you to alter the contents of the node before it is displayed to the user. In your module, just test to see if the node being viewed is a book node. If it is a book node, then add the contents of the book block to the node body. This can be done by: $book_toc = book_block('view', 0);. This command returns an array into the variable $book_toc. The book navigation (TOC) can now by accessed by $book_toc['content'].

All should be well.

This approach has two advantages:

  1. You don't have to modify core to do it.
  2. When you disable it, it's gone, when you want it back, all it takes is the push of a button. You are using the book module itself to create the TOC, so you aren't having to write any complicated code there.

Good luck!

- Corey

jaydunford’s picture

Hey thanks for the advice

I understand (in theory) what you suggest but haven't enough time to have a go at implementing it just yet.

The site that I am working on needs to go live next week and seeing so I haven't ever attempted creating a custom module I don't think it's a good idea diving in just now ; )

What I am going to do is disable the TOC menu from book pages and leave the prev / up /next menu where it is (at the bottom).

I intend to convince my clients that using the book navigation block is the best way forward for their new site (because it just seems to work and will update itself when they create new child pages - which is a huge bonus)

Thanks again
Jay

adampasz’s picture

I'm assuming after 2 years someone must have figured out how to do this. Any suggestions for Drupal 6 users?

coreyp_1’s picture

The ways I can think of off the top of my head:

1. modify your theme templates.

2. Contemplate.

3. This script cleverly implemented.

Maybe even a mixture of the three...

- Corey

adampasz’s picture

Thanks for the suggestions...

Method 1 doesn't seem to work because the book navigation gets stuck into the $content variable by the theming engine. I can't see a way to separate the book navigation out or move it around.

Method 3 looks like it involves building a new menu from scratch. Seems like quite a headache to do something so seemingly trivial.

I will look into Contemplate to see if that helps. It sounds promising...

navs’s picture

How can I build this custom module? Can you please help me with this same request? I too am trying to bring the links to child pages onto a right side nav bar.

A TOC on the right nav bar when any book is being views would be ideal. How can I do this?

Please help.
thanks
Navs

haaiee’s picture

Hello Jay,

I had the same problem that you did with another module (one that I build myself).
Creating a new region for the module worked very well for me:

1 Create a new region (called "contenttop" for instance).

in
.info you should now have lines that look something like this (depending on which regions you want):

regions[left] = Left
regions[header] = Header
regions[contenttop] = Content Top
regions[content] = Content
regions[footer] = Footer

2 add the $contenttop variable to page.tpl.php.

in page.tpl.php you should find where the variable $content is printed and change "$content" to "$contenttop.$content".
the line should now look simething like :
print $contenttop.$content

3 Clear the cache.

go to admin/settings/performance and click on the "clear cached data" button.

4 Move the module to this new region.

vinnie035’s picture

Alternatively, you could use something like:

<div class="content">
  <?php print $node->content['book_navigation']['#value']; ?>
  <?php print $node->content['body']['#value']; ?>
</div>

in your node template file (node-YOUR-TYPE-OF-NODE.tpl.php), instead of the usual:

<div class="content"><?php print $content; ?></div>

Then, optionally, you'll just have to modify book-navigation.tpl.php to suit your needs.

Hope that helps some of you.

bomarmonk’s picture

I am using a view field to embed a view of files into book pages, and this approach breaks the view field (the view is no longer displayed on the book page). I am using the view field module found here: http://drupal.org/project/viewfield Any ideas on how to make this node.tpl snippet work with a view field?

Vollzeitaffe’s picture

This solution works just fine for me. After I had some small troubles caused by not reading carefully enough everything works now according to my wishes.
For the protocoll:

  • browse to your theme directory
  • Edit the node.tpl.php file which declares how contents gets presented on your page.
  • search for the box <div class="content">...</div>
  • substitute its content with the two lines from above
  • additionally add
    <?php print $node->content['files']['#value']; ?>
    

    - otherwise your attachments wont show up

  • thats it so far
  • Additionally you can customize the book-navigation.tpl.php according to your needs. Besides I edited the following lines in my node.tpl.php:

 <?php 
	  $trimmed=trim($node->content['body']['#value']);
      if ($submitted and !empty($trimmed)): ?>
        <div class="submitted">
          <?php print $submitted; ?>
        </div>
      <?php endif; ?>

This causes Drupal only to show up author and creation date if the node contains a real article not only the navigation to subpages. of the book.

marblegravy’s picture

This is a really old post, but thought I would share the Drupal 7 solution for any newbies coming along and looking for the solution to moving the book navigation block out of the bottom of the default main content region.

In your node.tpl.php file if you'll just want to find the line that looks similar to this:

<?php print render($content); ?>

Then adjust it to look like this:

<?php 
hide($content['book_navigation']);
print render($content); ?>
<!-- Any other html code you want -->
<?php print render($content['book_navigation']);?>

This will print the book_navigation separately wherever you want it to go.

Aleksei’s picture

marblegravy,

Thank you so much!!!