1

I have a block with the id 'block-block-8'. In my template.php I would like to have a function that changes that block's content so I am able to add a dynamic "back to category link" (category needs to come frome the url) on my products page back to the category page.

Something like this:

function ga2012_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    case 'block-block-8':
      $block = array(
        'content' => '<a href="/order/4/workshops">Back to $_GET["category"]</a>',
      );
      break;
  }

  return $block;
}

Does someone has a working implementation of this code? Please ask me questions if I haven't been clear enough, thanks!

3

You might try with hook_block_view_MODULE_DELTA_alter which:

Performs alterations to a specific block

  • I enabled the PHP filter module and added the PHP code into the block via the admin interface. This works for me. – user5706 Jan 13 '13 at 15:58
1

In your case, the best solution is to use hook_block_view_MODULE_DELTA_alter as @Artur explained. But there is another way to to customize a custom bloc programmatically using an update function (inside a .install file) in drupal 7 by using:

$content = 'your new content';

$num_update = db_update('block_custom')
                ->fields(['body' => $content,])
                ->condition('bid', your_block_id, '=')
                ->execute();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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