Defining a custom page
In Drupal, there are routes that represent URL paths that Drupal interprets to return content. Modules can 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...
- Firstly, we'll set up the controller. Create a
srcfolder in your module's base directory and another folder namedControllerinside it.
Â
- Create
MyPageController.phpthat will hold the route's controller class:

- The PSR-4 standard states that filenames match the class names they hold, so we will create a
MyPageControllerclass:
<?php namespace Drupal\mymodule\Controller; use Drupal\Core\Controller\ControllerBase...