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 codimth.com !’
Add the following code to the codimth_controller.info.yml
file:
name: CodimTh Controller
description: Create a custom page in drupal 8
package: CodimTh
type: module
core: 8.x
Add the following code to the codimth_controller.routing.yml
file:
codimth.content:
path: '/hello'
defaults:
_controller: '\Drupal\codimth_controller\Controller\CodimthController::index'
_title: 'Create a custom page in drupal 8!'
requirements:
_permission: 'access content'
Add the following code to the codimth_controller/src/Controller/CodimthController.php
file:
<?php
namespace Drupal\codimth_controller\Controller;
use Drupal\Core\Controller\ControllerBase;
class CodimthController extends ControllerBase
{
public function index()
{
return array(
'#type' => 'markup',
'#markup' => $this->t('Welcome to codimth.com !'),);
}
}
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.