freez
freez

Reputation: 81

How i can modify $content data in Drupal 7?

how i can modify $content data in Drupal 7?

I want to change / modify the block content of the module: blog

I tryed in my template.php file:

function blog_block_view($delta = '') {
   return "Test, yes i am here";
}

But nothing happens...

Upvotes: 0

Views: 200

Answers (3)

user3406998
user3406998

Reputation: 16

As per following example you can modify in .module file.

function hook_block_view($delta = '') {
  // All of these are functionally identical.
  $block['subject'] = '';
  $block['subject'] = NULL; // Or just don't set.
  $block['title'] = '<none>'; // Undocumented, but works.
  // This will not behave as desired.
  $block['subject'] = '<none>';
  $block['content'] = array(
        '#theme' => 'feed_icon',
        '#url' => 'rss.xml',
        '#title' => t('Syndicate'),
      );
return $block; 
}

Upvotes: 0

Muhammad Reda
Muhammad Reda

Reputation: 27023

In order to change the $content of an existing block, you will need to create a custom module, with hook_block_view_alter() implementation.

Drupal.org example:

function hook_block_view_alter(&$data, $block) {
  // Remove the contextual links on all blocks that provide them.
  if (is_array($data['content']) && isset($data['content']['#contextual_links'])) {
    unset($data['content']['#contextual_links']);
  }
  // Add a theme wrapper function defined by the current module to all blocks
  // provided by the "somemodule" module.
  if (is_array($data['content']) && $block->module == 'somemodule') {
    $data['content']['#theme_wrappers'][] = 'mymodule_special_block';
  }
}

Upvotes: 1

oknate
oknate

Reputation: 1148

Here's the correct format.

Make sure to check the delta is correct, or else you may change more blocks than you mean to.

/**
* Implements hook_block_view().
*/
function mycustom_module_block_view($delta = '') {

  if ($delta == "mydelta"){
    $block['subject'] = 'The Greatest Block Ever Created';
    $block['content'] = array(
      '#markup' => "<h1>Here's some content</h1>",
    );
  }

  return $block;
}

Upvotes: 0

Related Questions