Extra Block Types (EBT) - New Layout Builder experience❗

Extra Block Types (EBT) - styled, customizable block types: Slideshows, Tabs, Cards, Accordions and many others. Built-in settings for background, DOM Box, javascript plugins. Experience the future of layout building today.

Demo EBT modules Download EBT modules

❗Extra Paragraph Types (EPT) - New Paragraphs experience

Extra Paragraph Types (EPT) - analogical paragraph based set of modules.

Demo EPT modules Download EPT modules

Scroll
14/04/2025, by Ivan

The content() function in the HelloController class will return markup text when the routing system calls the page.

In your module folder, you should have the standard PSR-4 folder structure /src/Controller, and inside this folder, you should have the controller file HelloController.php.
Thus, your controller file will be located at
/src/Controller/HelloController.php

You have the following code in the HelloController.php file:

<?php

namespace Drupal\hello_world\Controller;

use Drupal\Core\Controller\ControllerBase;

/**
 * Defines HelloController class.
 */
class HelloController extends ControllerBase {

  /**
   * Display the markup.
   *
   * @return array
   *   Return markup array.
   */
  public function content() {
    return [
      '#type' => 'markup',
      '#markup' => $this->t('Hello, World!'),
    ];
  }

}

This code alone will not do anything. It must be triggered by adding a routing file to our module. However, adding the controller to our code first is part of the general D8 philosophy: “Build the tool, then connect it.”

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.