Create a custom page with custom controller at /hello
that displays a title of ‘Create a custom page in drupal 8!’ and the following content: ‘Welcome to itblog.webdigg.com !’
Add the following code to the itblog_controller.info.yml
file:
name: itblog controller description: Create a custom page in drupal 8 package: webdigg type: module core: 8.x
Add the following code to the itblog_controller.routing.yml
file:
itblog.content: path: '/hello' defaults: _controller: 'Drupalitblog_controllerControllerCodimthController::index' _title: 'Create a custom page in drupal 8!' requirements: _permission: 'access content'
Add the following code to the itblog_controller/src/Controller/ItblogController.php
file:
<?php namespace Drupalitblog_controllerController; use DrupalCoreControllerControllerBase; class ItblogController extends ControllerBase { public function index() { return array( '#type' => 'markup', '#markup' => $this->t('Welcome to itblog.webdigg.org !'),); } }
Now clear your Drupal 8 caches. and you should be able to see the new page.
I hope you found this article useful. let me know if you have any questions and I’ll be happy to answer them.
Similar Posts:
- Make modules and themes compatible with drupal 9
- change canonical URL in drupal 8 & 9
- how to Programmatically update an entity reference field in Drupal 8 & 9
- create media entities and attach them to paragraphs in Drupal 8 & 9
- How to change entity before it is created or updated.
1,571