How to create custom Blocks in Drupal

Share

Generally custom block concept is used to set up block through module, once the module is uninstalled block gets disappeared.



This helps to make secure block content, also we can load dynamic content in block as per the requirement. The most important use of this block is that it can be placed in any site (module directory) and after enabling the module the block gets automatically created and rendered in block list (admin/build/block).

For creating custom block custom module is required.

Here, consider that we have our custom module with name “custom_module” that contains custom_module.info and custom_module. module files.

Some easy steps to create custom block:
1) Create block_info hook in cutom_module.module file.

This hook creates the information schema for block. Here, the $blocks array contains first block with information ‘Block Title’.

2)Now, create block_view hook to set content for block and to make it visible.

In second step, $delta parameter defines the block -id which is being requested.
$block[‘content’] section contains the content or information part for block that we want to display. In this part we can show result of function that return the content as per requirement.

After following above steps the block will automatically rendered in admin block list. Please note, Custom module should be enabled otherwise block will not render in block list.

Once the block is rendered in list we can set permission and region for that block as like other blocks. Also we can call a form or a view in a custom block.

Please feel free to login using google or facebook and create a forum topic to get your query answered in few hours here http://www.learn-drupal.in/forums/forum/drupal-forum-post-installation

Follow me

Sachin Wable

Sachin Wable is a technical blogger. He is blogging since 2010 & writes about Blogging, affiliate marketing & technical stuff. His blog learn-drupal.in receives 22,500 page views and visits from 1934 cities from 135 countries per year. (As per last years google analytics report.)
Follow me

Latest posts by Sachin Wable (see all)

affiliate_link

724 views

Leave a Reply

Your email address will not be published. Required fields are marked *