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:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.