Wednesday 12 April 2017

Drupal 7 Block Regions and Hidden Block Regions

HI,
  I think you have created blocks and placed that block in any regions. Sometimes we need to create some new block regions.
So first, how to create new block regions. It is very simple in drupal, 
Just go to your theme.info file and add the following line of code
  regions[REGION_MACHINE_NAME] = REGION NAME

So in this way, we can create many regions as our requirement.Now by adding these line and after clear the cache, we can see these region at block structure page and we able to assign blocks to these region but we can't see blocks on the page.Why????????
Because we haven't specified block region variable in page.tpl.php file. We have to print the region variable into page template file.
Just go to page.tpl.php file and just write the following code into template file, you need to keep in mind where are you witing this line.
<?php print render($page['REGION_MACHINE_NAME']); ?>


Hidden Regions

 Sometimes we need to create such block regions which are not allowed to a user place any block in it. we don't want to show these regions on block structure page or in simple words we can say that we don't want to allow the user to change the specific block placing on the page. What is the solution for this ???????
Yes, Hidden regions are there for helping us.
Hidden regions are not different functionality, it is similar to simple block regions.When we make a region as a hidden region then we can't see that region at block structure page.
Hidden regions are behaving same as simple regions except rendering on block structure page.

How to create hidden region, there are tow methods 

1. By theme.info file
regions_hidden[] = the_region_name
    Just writing this line into your theme.info file


2. By hook_system_info_alter()

We can make any region, hidden region by the help of this hook.

Just show your theme.info file there are two regions page_top and page_bottom, now see your block structure page, here you are able to see all block regions except both page_top and  page_bottom.
Why????

Just get the answer of this question, it will help you to understand the concept of hidden block regions.


If have any questions, please feel free to ask in comments.

No comments:

Post a Comment

Thanks!