O'Reilly logo

Drupal 8: Enterprise Web Development by Chaz Chumley, Matt Glaman, Richard Jones, Nick Abbott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining a custom page

In Drupal, there are routes that represent URL paths that Drupal interprets to return content. Modules have the ability to define routes and methods that return data to be rendered and then displayed to the end user.

In this recipe, we will define a controller that provides an output and a route. The route provides a URL path that Drupal will associate with our controller to display the output.

Getting ready

Create a new module like the one in the first recipe. We will refer to the module as mymodule throughout the recipe. Use your module's name as appropriate.

How to do it…

  1. Firstly, we'll set up the controller. Create a src folder in your module's base directory and another folder named Controller inside it.
  2. Create MyPageController.php ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required