0
votes

I'm running a pretty large drupal 7 website.

I'd like to implement esi support on blocks by wrapping each block content with tags.

Now I can do that pretty easilly with theme_preprocess or hook_block_view_alter, but this only works if the block "content" variable passed to the drupal template is a string. If that variable is an array for instance it's imposible to wrap it in those tags, because this array is parsed in the template.

So the only way I could get it working is after getting the block value returned from the template. But I don't think the damn drupal even supports that... without hacking the core and outputting the tags before and after template incluision. But I really don't want that... so does anybody have an idea how would I be able to achieve this goal ?

Thank you very much!

1
obviously how would I achieve the goal described in the articleTadej Magajna

1 Answers

2
votes

If the block content is an array you can add a #prefix and #suffix to it:

function mymodule_block_view_alter(&$data, $block) {
  if (is_array($data['content']) {
    $data['content']['#prefix'] = '<div class="my-class">';
    $data['content']['#suffix'] = '</div>';
  }
  else {
    $data['content'] = '<div class="my-class">' . $data['content'] . '</div>';
  }
}

The #prefix and #suffix will be honoured for any Drupal render array when it's passed through render() (or drupal_render()) so this should solve the problem.