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…
- Firstly, we'll set up the controller. Create a
src
folder in your module's base directory and another folder namedController
inside it. - Create
MyPageController.php ...
Get Drupal 8: Enterprise Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.