Remove Table of Contents from Drupal Book
Submitted by greggles on Fri, 2006-03-03 16:48.
Continuing on from the project I just mentioned...I wanted to remove the list of pages (which is analogous to a table of contents) from the book pages. On this particular site I'm using the book block on the right hand side, so having this information on the bottom of top level page makes for duplication of links and just seems plain funny. Below is the relevant diff -u on the subject:
Edit: This is actually a really bad idea. See the comments below for the right way to do it for Drupal 6.
@@ -469,9 +469,9 @@
if ($node->nid) {
$output .= '
<
div class="book">';
- /*if ($tree = book_tree($node->nid)) {
- if ($tree = book_tree($node->nid)) { $output .= '
'. $tree .'
'; - }*/ + }
if ($prev = book_prev($node)) {
$links .= '<div class="prev">';






how does this work?
I'm having trouble trying to do the same thing on a Drupal site I'm developing. I'd like to remove the Table of Contents that is always generated.
I was glad to find this page, but I can't seem to figure out how to implement the code above you've suggested. I quite a beginner in these things and could really use some more specific instructions.
I've been trying to make adjustments to the book.module file, based on your code, but I don't seem to be able to get it right.
Any advice would be greatly appreciated.
Thanks!
really bad idea
This is actually a really bad idea. I'm not sure how to remove the table of contents without hacking the book module, but this is the wrong way to do it, I assure you :(
remove book links
Warning! This is at own risk... (It worked for me. For now...)
(for drupal 6.1)
<?php if ($tree || $has_links): ?>" class="book-navigation">
<?php if ($prev_url) : ?>
<?php print $tree; ?>
<?php if ($has_links): ?>
" class="page-previous" title="<?php print t('Go to previous page'); ?>"><?php print t('â¹ ') . $prev_title; ?>
<?php endif; ?>
<?php if ($parent_url) : ?>
" class="page-up" title="<?php print t('Go to parent page'); ?>"><?php print t('up'); ?>
<?php endif; ?>
<?php if ($next_url) : ?>
" class="page-next" title="<?php print t('Go to next page'); ?>"><?php print $next_title . t(' âº'); ?>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
If this turns out to be not a very smart thing to do, please notify me! ;)
close to right...here's the "Drupal way" to do it
This is almost the right answer. Basically (as my warning above states) what you want to do is not edit the original code, but use Drupal's override system. When you edit the original code then you have to be sure to re-apply the change whenever you update Drupal (and you are going to update Drupal when Drupal6.2 is release right...
So...by using a theme override, you can apply this in a way which will still work after you've upgraded your site.
Hmmm... yeey thanks...
Yeey. It worked. I thus restored the original file in the drupal module and used the theme override. Thank you for the advice! (And do update your blogposts, when you find a solution for a problem, it helps the folks googling for the exact same problem, and thus solution... ;))
Thanks again,
Vint
Removing Table of Contents from Drupal 5 Book
To implement this in Drupal5, you need to override the "theme_book_navigation" method in your template.php file. Copy this from "book.module", and replace "theme" with your theme name as per usual.
To remove the tree, simply comment out this line:
$tree = book_tree($node->nid);There is however one gotcha. Drupal's link function strips out the text of the navigation links because it doesn't like the arrow symbols this uses. Simply change them to "<" and ">" and it should work without a problem.
Post new comment