Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

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.

 

Drupal 8 Create a custom page

I hope you found this article useful. let me know if you have any questions and I’ll be happy to answer them. 

Comments

Add new comment

Restricted HTML

Riadh Rahmi

Senior Web Developer (Drupal & Laravel)

I am a senior web developer, I have experience in planning and developing large scale dynamic web applications especially in Drupal and Laravel.

Web Posts

Search

Page Facebook