// 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:
- How to create custom block in Drupal 8 programmatically
- Drupal: Creating a Computed Entity Field
- How to Add target attribute to form and submit buttons in Drupal 8 / 9
- How to add class to content field link in Drupal 8 / 9
- How to remove title block for a certain page in Drupal 8
647