注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

John's Blog

天空,有梦就可以飞翔!

 
 
 

日志

 
 
关于我

刚走出校园的毕业生,就读计算机网络专业,对网站建设有一定的基础。开始探求Drupal已有一段时间,对Drupal的发展很是看好。现就职于深圳慧衡科技有限公司(intematrix.cn),它是一家专门服务于中国及海外中小企业的网络营销分析和优化服务提供商。 QQ交流群:44581272

网易考拉推荐

Drupal:Placing the contents of a block in any location  

2010-08-01 15:43:38|  分类: drupal学习 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

PLEASE NOTE These snippets are user submitted. Use at your own risk. For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.

If you want the contents of a block to appear within a page you can use the following snippet:

 


<?php
$block = module_invoke('module_name', 'block', 'view', 0);
print $block['content'];
?>

 

To specify which block from which module, you simply edit the two following variables in the first line:

module_name = The name of the module
The number = Is the $delta of the block

For example to call the block on the Font Size module use:

 


<?php
$block = module_invoke('fontsize', 'block', 'view', 0);
print $block['content'];
?>

 

Or for example to display who is a new user:

 


<?php
$block = module_invoke('user', 'block', 'view', 2);
print $block['content'];
?>

 

Showing more than the block body

Calls to $block['content'] only provide the block body. Here's 2 ways to provide more.

1. In comments, GWL shows how to wrap the $block data in divs. It also checks for empty content and hides empty blocks:

 


<?php
$block = module_invoke('block', 'block', 'view', 1);
  if ($block['content']) {
    $output = "<div class=\"front-page-block\">\n";
    $output .= "<div id=\"front-block-title\"><h2>".$block['subject']."</h2></div>\n";
    $output .= "<div class=\"content\">".$block['content']."</div>\n";
    $output .= "</div>\n";
    print $output;
  }
?>

 

2. On a different page japanitrat shows how to call theme() function with a cast to object.

 


<?php
$block = (object) module_invoke('[target_module]', 'block', 'view', "[target_block_ID]");
print theme('block', $block);
?>

 

The theme call will provide the block wrapped in your theme's block.tpl output (assuming php template). However, it may not look exactly like a block in a given sidebar (say, block appearing in center content, but rendered as if a left sidebar block). Usually this difference comes from the absence of variables determining HTML and CSS styling written in the block.tpl file.

To make a block appear in one place, themed as if for another region, that would require inspection of your theme's template.php that is outside the scope here. For an example, review the Acquia Marina template.php, line 302, 'template_preprocess_block(), for where the 'rounded block' CSS class comes from, then triangulate with that theme's block.tpl.php.

  评论这张
 
阅读(236)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016