// src/Controller/ModulenameController.php namespace Drupal\modulename\Controller; use Drupal\Core\Controller\ControllerBase; class ModulenameController extends ControllerBase { public function helloWorld() { return [ '#markup' => 'Hello, World!', ]; } }
# modulename.routing.yml modulename.hello_world: path: '/hello/world' defaults: _controller: '\Drupal\modulename\Controller\ModulenameController::helloWorld' _title: 'Hello, World!' requirements: _permission: 'access content'
Or using drush:
# vendor/bin/drush generate controller
Similar Posts:
- Drupal: Creating a Computed Entity Field
- How to create custom block in Drupal 8 programmatically
- How to change Drupal core files
- How to remove title block for a certain page in Drupal 8
- How to remove title block for a certain page in Drupal 8
539