开发者

Drupal: how to pass variable from node to block?

I'd like to do in

  1. do some processing of node fields in node.tpl.php
  2. save it to a variable
  3. and display开发者_如何学Go in a block that is loaded after the node (on the same page).

How to pass a variable from a node to a block?


Since you're running Drupal 7, you have access to the new hook_page_alter() function, from either a custom module or theme. By implementing this, you can easily move parts of the main content area (eg, the node), into any number of different blocks. You'll want to use the show(), hide() and render() functions to properly hide content.

Alternatively, using show() and hide() from within your node.tpl.php template should properly hide the elements, and then you could grab the node object from your block using the menu_get_object() function.

There is normally a video available on hook_page_alter() here, but the site is down at the moment.


do some processing of node fields in node.tpl.php

A purist would say that you shouldn't be doing it there. hook_node_load() can be used for processing of fields.

Then you can just use menu_get_item() in your block to get the $node object and access any values you have added to it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜