

If you get the ‘Page Not Found’ error, then clear the cache by navigating to admin->configuration->performance. To check if it functions properly, visit the path you specified in your routing file, that is /welcome/page. Now Login to your Drupal site and enable your module. In this folder, create a file named "WelcomeController.php" with the following content: 'Welcome to our Website.' Step 4: Adding a ControllerĬreate a folder "modules/custom/welcome_module/src/Controller". User needs to have to be able to view the page. Under requirements, we specify the permission of the accessing. Under defaults, we have two things: the _controller which references a method on the WelcomeController class and the default page title (_title). Under path, we specify the URL path we want this route to register. _title: 'Welcome to My Module in Drupal 9' _controller: '\Drupal\welcome_module\Controller Next step is to add a welcome_ file under the "welcome" directory: welcome_module.welcome:

Package: Custom - (Mentioning that this is a custom module)Ĭore_version_requirement: ^8 || ^9 - (Drupal version) Step 3: Creating the routing file with routing.yml Type: module - (Declaring that this is a module or theme)ĭescription: Custom Example Drupal 9 Module (Description of the module)


Name: Welcome Module (The name displayed on the modules list in Drupal) name: Welcome Moduleĭescription: 'First Custom Drupal 9 Module.' Here is our welcome_ file created under " welcome" directory we created in Step 1. I’ll create a yaml file like this welcome_. We have to create a yaml file with the machine name of our module for Drupal to be able recognize the module. Step 2: Get noticed with the info.yml file
