how to override $block->content in drupal?

2019-07-30 06:35发布

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.

3条回答
SAY GOODBYE
2楼-- · 2019-07-30 06:52

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";
      }
    }
  }
查看更多
走好不送
3楼-- · 2019-07-30 06:53

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";
          }
     }
}
查看更多
Ridiculous、
4楼-- · 2019-07-30 07:03

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.

查看更多
登录 后发表回答