How to create a custom page programmatically in Drupal 8


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 !’

Add the following code to the 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:

  path: '/hello'
    _controller: '\Drupal\itblog_controller\Controller\CodimthController::index'
    _title: 'Create a custom page in drupal 8!'
    _permission: 'access content'

Add the following code to the itblog_controller/src/Controller/ItblogController.php file:

namespace Drupal\itblog_controller\Controller;
use Drupal\Core\Controller\ControllerBase;

class ItblogController extends ControllerBase
    public function index()
        return array(
            '#type' => 'markup',
            '#markup' => $this->t('Welcome to !'),);

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:


How useful was this post?

Click on a star to rate it!

Average rating 1 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

Scroll to Top