how to override $block->content in drupal?

丶灬走出姿态 提交于 2019-12-11 06:55:54

问题


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.


回答1:


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.




回答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";
      }
    }
  }



回答3:


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";
          }
     }
}


来源:https://stackoverflow.com/questions/5320092/how-to-override-block-content-in-drupal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!