Michael

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.

  1. Create a custom module. No need to mention that you will have mymodule.info and mymodule.module files. You will also need to create mymodule-page.tpl.php file in the templates folder inside your module folder. We highly recommend putting template files into a separate folder.

  2. Open mymodule.module file. Define you custom URL path, and let Drupal know, which function will return the content of your new page.

  3. Define a callback function. The keys in the $vars array will be available as variables in your template file.

  4. Define which template file Drupal should use to display the content of your page.

    [gist:daeb72ad9177527b7fa9]
  5. Open templates/mymodule-page.tpl.php and create HTML structure for your new page. You have already defined available variables in your callback function.

  6. Enable your new module and flush the caches. To view your new page, go to yoursite.com/mymodule-page.

More blog posts by Michael Kudenko

Ansible is a great tool for automating tasks executed either locally or remotely. Today we will talk about using Ansible in conjunction with Vagrant for setting up a local development environment.
When you're developing a system that is supposed to work with multiple content types (or any other data structures), polymorphism can be quite helpful. Today we'll talk about how to organise your database schema and use Eloquent to implement polymorphic relations between your models.
Previously we have talked about the benefits of using virtual machines for local development and how Vagrant and Ansible help you manage your VMs. In this post we will talk about the Vagrant part of our setup.