drupal8: create module with multiple route and custom Route Contoller Twig Template

In the most example of drupal8 you will experiment the Hello World module. This is just a demostration how you can create your custom module within the new drupal8 concept.

But your application can be more complicated as just a Hello World module, you want may be create one module, multiple route and a custom twig template for each route

User case is if you want to create your own module but managing a multiple Route within one module.

When you add a new yaml file you should uninstall the modul and insatll it again. I haven’t found other solution for this right now ! This will help you if you can’t see any changes when you add some configuration or yml files.Or when you get following error:
Theme hook YOUR-TEMPLATE not found.

Let say you want to create a module to manage contact and edit them. My Module in this case is named “mymodule”

Let start to create the diffrent route in “mymodule.routing.yml” file:

 

Add your Conroller in src folder with the name ContactController.php:

Create following yml file “mymodule.module”:

At the end just create the Twig templates within your templates folder:

templates/contact_edit.html.twig

templates/contacts_show.html.twig

So now, you are able to create diffrent routes and templates using Drupal8 and transfer variables from the controller to the twig template
using your own business logic operations.