How do I programmatically create a page in drupal 8?

3
(1)
// src/Controller/ModulenameController.php
 
namespace DrupalmodulenameController;
 
use DrupalCoreControllerControllerBase;
 
class ModulenameController extends ControllerBase {
  public function helloWorld() {
    return [
      '#markup' => 'Hello, World!',
    ];
  }
}
# modulename.routing.yml
 
modulename.hello_world:
  path: '/hello/world'
  defaults:
    _controller: 'DrupalmodulenameControllerModulenameController::helloWorld'
    _title: 'Hello, World!'
  requirements:
    _permission: 'access content'

Or using drush:

# vendor/bin/drush generate controller

Similar Posts:

647

How useful was this post?

Click on a star to rate it!

Average rating 3 / 5. Vote count: 1

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

Scroll to Top