Darren Mothersele

London based Drupal Web Developer
Drupal.org Google+ Facebook Twitter GitHub LinkedIn RSS Feed

Theme Blocks module now on drupal.org

Now you can define Drupal blocks in your themes! With the Theme Blocks module I just submitted to drupal.org you can include blocks with your custom Drupal themes.

Sometimes you want a simple block for your Drupal site, and you have to create a module just to implement hook_block(). For simple blocks you end up creating the same code again and again for every site. Defining the template in hook_theme() then implementing hook_block() to make Drupal aware of your block. I have abstracted this process to make custom blocks as easy as adding a template file to your theme and a line to your theme.info file. See the project page on Drupal.org for more information.

Someone asked why not just add the block as a custom block using the Drupal block administration options? Well, you can do this, but by providing the block in your theme you benefit from version control on the source code, you can distribute the block with your theme, and even enable the block by default.

Hi,
I Like your module but I'm searching about all variables that could be used in the block template. I mean more detailed than "$content".

for Example : using the "form block" module I can have a user registration form in a block, I want to change the layout of this block (deleting the fieldset grouping). Like with the "form node template" module, you can define your own layout using $form array.

I don't know if you understand what I mean, my english is poor...

Thanx for your answer!!!

Jonathan.

Offtopic, but I think I understand what you mean. If you are wanting to edit a form you need to implement hook_form_alter() see the API docs on api.drupal.org for more information and examples.

You can always look what variables are available from a template by adding the following line of code:

<?php
print_r
(get_defined_vars());
?>

but of course only do that in dev mode, not on a live site!

Post new comment
The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

Recent comments
Latest Posts