1

I'd like to build a Drupal 7 module that generates a block which contains (along with some static HTML to be used as template for a JavaScript library) a node-specific value to be passed on to a web service. (The web service will return relevant data for the contents of the node.)

How should a block receive node-specific data? Module configuration seems to be global, and blocks cannot be configured individually.

Should I modify the main content-type of the node by adding this "node-specific data" as an extra field even if this value is only used in my module?

1 Answer 1

1

Use the Block API to add the blocks

i.e:

Use menu_get_object to get the node object for that page.

e.g:

function mymodule_block_view($delta){
  $block = array();
  switch($delta){
    case 'my_delta':
     if ($node = menu_get_object('node') && $node->type == 'my_type') {
       $block['subject'] = t('Example block on %node', array('%node' => $node->title));
       $block['content'] = render(field_view_field('node', $node, 'body')); // for example
     }
    break;
  }
  return $block;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.