Define a Custom Page in Drupal 8

Public

Define routing in page_example.routing.yml file:

Get raw version
php
  1. page_example.content:
  2. path: '/example-page'
  3. defaults:
  4. _title: 'Page Example Title'
  5. _content: '\Drupal\page_example\Controller\PageExampleController::content'
  6. requirements:
  7. _permission: 'access content'

Extend PageContoller:

Get raw version
php
  1. namespace Drupal\page_example\Pages
  2. use Drupal\page_controller\Controller\PageController;
  3.  
  4. class PageExampleController extends PageController {
  5.  
  6. /**
  7.   * Implements \Drupal\page_controller\Controller\PageController::content().
  8.   */
  9. public function content() {
  10. // Define output:
  11. $output = t(‘Page example content.);
  12.  
  13. return array(
  14. '#markup' => $output,
  15. );
  16. }
  17. }