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

lotus.content:
  path: '/hello'
  defaults:
    _controller: '\Drupal\lotus\Controller\HelloController::content'
    _title: 'Hello Drupal!'
  requirements:
    _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

https://gist.github.com/prasadshir/be232c55197c5011b074ea4efa1f416d

Contact supportStill need assistance? Contact Acquia Support