Using node variables in another block?

by nyoz   Last Updated January 10, 2018 05:07 AM

I'm trying to create a block which would include informations on the displayed node like author picture, name, and points (using Userpoints module), the creation date, and some other infos contained in created fields for certain types of nodes.

The thing is that I want to display this block in my sidebar-second (my theme is based on bartik, except that sidebar-second is included in the <div id="content"></div>).

But I don't manage to use variables available in files like node.tpl.php. For instance, when I try to display the author picture in the block, I write <?php print $user_picture; ?> but nothing appears...

Here's what I created on photoshop and I'd like to translate into Drupal (if it can help, and yes it's in French ^^) :what I want finally

Thks !

EDIT : I'm using D7.

EDIT by nyoz : Ok, so it seems like Multiblock is a good beginning. README.txt says the following :

DEVELOPING MULTIBLOCK-ENABLED BLOCKS: Multiblock should successfully clone any regular block created with the block API. However, if you clone a regular block that implements a hook_block_save or hook_block_configure hook, the custom block settings of one block instance will overwrite the settings of another. To get around this, you can make a block "multiblock enabled." To do this, you should add a 'mb_enabled' key with a value of true in hook_block_info to each multiblock enabled block you are creating. Next, add an optional $edit argument to your hook_block_view and hook_block_configure functions. Once you do this, the instances you create will get the block instance ID passed in the $edit variable for the view, configure, and save $ops. This will let you save and load different data to different instances based on this instance ID. It is passed in with the 'multiblock_delta' key with the following format: $edit['multiblock_delta'] = array( '#type' => 'value', '#value' => $block_id );

Example implementation of hook_block_info: function hook_block_info() {
$blocks['powered-by'] = array( 'info' => t('Powered by Drupal'), 'weight' => '10', 'cache' => DRUPAL_NO_CACHE, 'mb_enabled' => TRUE, ); return $blocks; }

... So, I created a custom module containing :

function hook_block_info() {
  $blocks['content'] = array(
    'cache' => DRUPAL_NO_CACHE,
    'mb_enabled' => TRUE,
  );
  return $blocks;
}

I've also tried $blocks['main'] $page['main'] $page['content'] -with return $page-. BUT NONE OF IT WORKED (the block is still not multiblock enabled when I look in the instances list).

DO YOU HAVE ANY CLUE PLEASE ? Thks!

Tags : 7 nodes blocks


Answers 1


Try MultiBlock module.

MultiBlock module solves this problem by allowing you to create multiple Block Instances of already existing blocks. Please read the README for more information.

drupality
drupality
June 20, 2011 19:32 PM

Related Questions


Drupal Menu usign Carousel

Updated June 24, 2016 08:03 AM


How to find the count of items in a block?

Updated June 11, 2015 08:03 AM

How to use Insert Block module on Drupal 8?

Updated March 30, 2017 22:07 PM

How to link on block

Updated February 17, 2016 01:03 AM