A Hello-World custom page module with Drupal Console

This a very common and basic task we can accomplish easily with DrupalConsole.
We need to have a custom module which contains the code for the following items:

  • A controller for giving a url to our HelloWorld page
  • A routing file in which the that url is related to the class of the controller

All of this can be quickly done with the DrupalConsole command generate:controller , but first let's generate our module

generating a module with DrupalConsole

Right, we need to generate our controller now

generating a controller with DrupalConsole

So, let's take a look to our controller

Drupal 8 controller

In the hello() method we can print the content of the page

Meanwhile, the routing file looks like

A routing file in Drupal (

We can see how DrupalConsole indicated the method as entry point for the controller and set the permissions. The url is in the path key.

That's all! We already have our new and shiny custom page at /hello_world location!

A hello-world page in Drupal 8



Añadir nuevo comentario

Type the characters you see in this picture. Type the characters you see in the picture; if you can't read them, refresh the CAPTCHA or submit the form and a new image will be generated. Not case sensitive.