Drupal 7: Custom Module – Part 2

This is second and last part in Custom Module series. We will use custom module that we created in last tutorial and create a custom front page for a freshly installed Drupal installation

[b]Requirements:[/b] https://www.rattanpal.com/content/drupal-7-custom-module-part-1.aspx

Create a new template called [i]sites/all/theme/page–front.tpl.php[/i]. This template will override the default template and will be used for any page that we decide to use as front page

Edit [i]mymodule.info[/i]. We will ue this file to add custom page. Following code needs to be added to this file. Comments have been added to all code snippets which describe all the items in each function.


Clear Drupal cache for Drupal to read new changes to this file.

If you haven’t already then enable this module in admin/modules.

Now go to Site Information (admin/config/system/site-information) and add “home” in “Default front page”. This will ensure that this new custom home page will become our front page and that will also make Drupal use page–front.tpl.php as template

Before your front page can be accessible to anonymous users, you need to give permissions to anonymous users to access this new custom page. To allocate permissions, go to User Permissions (admin/people/permissions). Look for “Access mymodule Home Page” (title of the page). Now check permission box for anonymous user and save permissions.

Voila!. You have just changed your site’s front page to be a custom page. You can add your content directly in page–front.tpl.php or in mymodule_home() function.

This concludes our 2 part series on how to add Custom Module and Custom front page.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.