views:

17

answers:

3

I am trying to modify drupal comment form so that just above the the form I can show a regions and add more blocks to that region (say some promotional banners).

I am doing this in template.php I have a working themename_comment_form function and can set $form['intro']['#value'] to the value I want. I also know how to create a new region.

What I am struggling is to get the value of that region (say $above_comment_form) and make it available inside themename_comment_form (something like $form['intro']['#value'] = $above_comment_form;) I have tried preprocess_page, preprocess_node to set the value like $vars['above_comment_form']=$above_comment_form but no luck.

+1  A: 

To create a region, you need to add it in your module's .info file. If you don't have any regions defined, the default is to have 5 available:

  • left
  • right
  • content
  • header
  • footer

If you want to add/remove regions you will need to write all the regions you want in your theme. So to include the custom region you would need to have this in your .info file:

regions[header] = "Header"
regions[left] = "Left sidebar"
regions[content] = "Content"
regions[right] = "Right sidebar"
regions[footer] = "Footer"
regions[above_comment_form] = "Above the comment form"

Now regions are only available in your page.tpl.php by default. You can get the blocks in a region that's available to the user by using theme_blocks. So in your preprocess_nodefunction you would need to add:

$vars['above_comment_form'] = theme('blocks', 'above_comment_form');

Then in your node.tpl.php you can do this:

<div id="above_comment_form">
  <?php print $above_comment_form; ?>
</div>

That should accomplish your task.

googletorp
A: 

Thanks for your answer but that is not what I am looking. Perhaps I was not clear

The part to add the region is fine. I already got it done. However the region needs to be before "comments form" and not below node. By using preprocess_node region gets attached to node. So your solution will produce

node body region:above_comment-form comments list comment form

What I am looking for node body comments list region:above_comment-form comment form

Comment_form is themed inside template.php. So somehow I want the variable $above_comment_form available inside that function (theme_comment_form) to make it working.

ajayg
A: 

The rendering of regions happens very late in the call stack so most times it is not possible to include them in something like a theme function or a form_alter.

However you can render individual blocks in those, so if you are looking to add a specific block using something like:

$block = module_invoke('block', 'block', 'view', 26);
print $block['content'];

Which will work in theme functions and templates. I tried doing something simular and dug pretty deep in the page rendering to look for the functions that rendered the regions, and it was either not possible, or not worth it to try to render the region earlier in the stack.

mirzu

related questions