Hi,

There is a theme I'm developing and I need to make some changes in a block, in every block. So the best way to do it is prior rendering. In a block render array, right?

How do I get to edit block render array in theme? any hook in template.php maybe?

Comments

nevets’s picture

It depends on what the changes are, your theme could use a custom block.tpl.php

Daugilas’s picture

No, template file won't work.
My blocks needs to be checked first if they need some changes and that would be too complicated and definitely not efficient to do in block.tpl.php.

nevets’s picture

Without know what types of changes you want to make it would be hard to advise.

Daugilas’s picture

Well ideally I would like to access/edit block render array in theme layer. I imagine it should be possible in template.php?.

And what do I need to do. One of the things is to alter the title of the block, but the trick is, I need to extract that title from other content of the block. Also depending on few other parameters determine how to alter the title and add some additional elements like class names... It is really too complicated to explain everything in detail here.

ns47731’s picture

You can pre-process blocks before they are outputted for rendering by implementing hooks in the template.php. In the code below I am using a sub theme of zen and my template.php is located in the root directory of my sub-theme. But according to forms it can be located in the /template directory and sometimes named template.tpl.php.

My theme is named McKenzieDental note the hooks name with relation to the theme name(important). Heres the code ive been using to understand the hierarchy of $variables:

<?php
function McKenzieDental_preprocess_block(&$variables, $hook) {
  echo "<script>".print_r($variables, true)."</script>";
}
?>

There are much more preprocess hooks if you would like I can post them, otherwise download the zen theme and look in /zen/STARTERKIT/template.php and read the comments in that file. Super informational and extremely useful.

Good luck.

heresh’s picture

subscribe