How to create a custom page in Drupal
Here is a simple example of how to take your first steps in custom Drupal development, by creating a custom page within your own module.
In order to create a custom page, simply follow the steps below.
-
Create a custom module. No need to mention that you will have
mymodule.infoandmymodule.modulefiles. You will also need to createmymodule-page.tpl.phpfile in thetemplatesfolder inside your module folder. We highly recommend putting template files into a separate folder. -
Open
mymodule.modulefile. Define you custom URL path, and let Drupal know, which function will return the content of your new page. -
Define a callback function. The keys in the
$varsarray will be available as variables in your template file. -
Define which template file Drupal should use to display the content of your page.
[gist:daeb72ad9177527b7fa9] -
Open
templates/mymodule-page.tpl.phpand create HTML structure for your new page. You have already defined available variables in your callback function. -
Enable your new module and flush the caches. To view your new page, go to
yoursite.com/mymodule-page.