Pergunta

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 in a block that is loaded after the node (on the same page).

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

Foi útil?

Solução

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.

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top