Create a custom page

Tutorial Goal

Lesson Goal:

D7 Code

Add the following in lotus.module file

* Implements hook_menu()

function lotus_menu() {
    $items['hello'] = array(
      'title' => 'Hello Drupal!',
      'description' => 'Landing Page for Lotus Module',
      'page callback' => 'lotus_hello_view',
      'access arguments' => array('access content')
    return $items;

* Page callback function

  function lotus_hello_view() {
    return 'Welcome to my website!';

D8 Code

1. Add the following in lotus.routing.yml file

  path: '/hello'
    _controller: '\Drupal\lotus\Controller\HelloController::content'
    _title: 'Hello Drupal!'
    _permission: 'access content'

2. Add the following in lotus/src/Controller/HelloController.php file

namespace Drupal\lotus\Controller;

use Drupal\Core\Controller\ControllerBase;

class HelloController extends ControllerBase {
  public function content() {
    return array(
        '#type' => 'markup',
        '#markup' => $this->t('Welcome to my website!'),

Gist Link

Contact supportStill need assistance? Contact Acquia Support