0

This is the first time i'm making a module for drupal. In my module I create a block with a vertical menu in it. I would like to place the block glued to the left of the screen (out the wrapper).

So far i tried to make my own region in the module (which worked) but I can't get the region to appear in the website. I know i would have to do this in the page.tpl.php from the theme, but I'm trying to do this through my module only.

So is there a way to make the website take the region? Is there a other/better way to place the block to the left?

thanks in advance! TL

1

You have to edit your theme's template to create a new region.

You will need to add something like:

<?php print render($page['your_region']); ?>

Without this nothing in that region will ever get rendered.

You will also need to add it to your themes .info file.

For more information see: How do I create custom regions in a theme?

5
  • Where do I have to put that code? – TLammar Apr 23 '14 at 12:49
  • And like I said, I would like not to adapt any oh the theme files :) – TLammar Apr 23 '14 at 12:50
  • If you want to add a new region you have to modify your theme. No way around that. That code would sit in your page.tpl.php file. – Felix Eve Apr 23 '14 at 12:52
  • Okaaj thanks! Is there another way to place the bloxk there, without a region ? – TLammar Apr 23 '14 at 12:57
  • Whilst it is possible to render blocks directly into a nodes content or a template it is rather missing the point of the whole block system. Generally themes are there to take care of what your site looks like and what regions are available, and modules are there to offer additional functionality. Your module should just create the block - but it is down to the theme to decide where it should be rendered. If you want to create new regions then you should make a new theme instead. – Felix Eve Apr 23 '14 at 13:03
0

Making sure the region is in the .info file, and rendering should work to get it displayed.

You could put the block in whatever existing region you alrdy have, and 'pull it out' using purely CSS, using position:absolute and go from there.

Or, still use a separate region, and combine the output of that region, with the output of a 'default' region you have, using code.

While both work, you should avoid them, and stick to adding another custom region. Then make sure your template puts it in the right place. If you really don't want to touch the theme, maybe you should think of working with a sub-theme instead. You'll still need to edit the templates to get the additional regions, but at least you'll have the original theme next to you for reference ( or whatever the reason is you don't want to change your theme files ). Read up on sub-themes here

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.