Use Config in Block Display

Last updated on
29 March 2024

To make use of the configuration of instances of the block, we can modify the build() method of the HelloBlock class:

  /**
   * {@inheritdoc}
   */  
  public function build() {
    $config = $this->getConfiguration();
    
    $name = $config['hello_block_name'] ?? $this->t('to no one');

    return [
      '#markup' => $this->t('Hello @name!', [
        '@name' => $name,
      ]),
    ];
  }

Help improve this page

Page status: No known problems

You can: