1

Now, if i want to override the $block->content which is generated by the Book module... how can I override it and customize the title list? thank you.

Laxman13
  • 5,226
  • 3
  • 23
  • 27
runeveryday
  • 2,751
  • 4
  • 30
  • 44

3 Answers3

5

You can use the preprocess_block function

function phptemplate_preprocess_block(&$vars) {
  if (isset($vars['block'])) {
      print_r($vars);
    }
  }

And dig into those results.

About the content, is this is a module generated block, I hope that $content is renderer using a theme() function, so you just need to alter it.

Haza
  • 2,991
  • 1
  • 16
  • 13
2

you can use a preprocess_block function

function yourthemename_preprocess_block(&$vars)
{
     if(isset($vars['block']))
     {
          //i have override a footer_block 
          if($vars['block']->region == 'footer_block')
          {
              $vars['content] = "Please Enter Some data";
          }
     }
}
Mehul Jethloja
  • 637
  • 4
  • 9
2

The $vars argument will have all the information about the blocks being themed. In your case you want the module to be "book".

function phptemplate_preprocess_block(&$vars) {    
    if (isset($vars['block'])) {
      if($vars['block']->module == 'book') {
        $vars['block']->content = "My new content";
      }
    }
  }
PPC-Coder
  • 3,522
  • 2
  • 21
  • 30
  • Good one PPC-code, I knew about phptemplate_preprocess_node, but phptemplate_preprocess_block looks interesting. Does all the entities in drupalhave preprocess functions? – Gokul N K Mar 16 '11 at 19:26
  • They only apply to theming hooks implemented as templates (plain theme functions don't get preprocessors). See this http://stackoverflow.com/questions/2383865/how-do-i-use-theme-preprocessor-functions-for-my-own-templates – PPC-Coder Mar 17 '11 at 04:42
  • PPC-Coder,i'm sorry, i out you code in my theme's template.php.but it can't work. – runeveryday Mar 17 '11 at 04:56
  • What's not working? I just added a Book navigation block to my page and was able to change it's content to "My New Content". – PPC-Coder Mar 17 '11 at 05:45
  • i have installed the DHTML Menu,and make it effect to the book navigation block. – runeveryday Mar 17 '11 at 06:21
  • if i disabled the DHTML Menu,it can output the "My New Content". but i want to use the DHTML Menu and can output the "My New Content". how should i do, thank you – runeveryday Mar 17 '11 at 07:52
  • I'm not familiar with DHTML Menu but if it is also affecting the Block output and you want to keep it you can still do some string manipulation to modify ti however you want. Like this (or something more elaborate): $vars['block']->content = "My new content" . $vars['block']->content; – PPC-Coder Mar 19 '11 at 01:10