Show the site name in a custom block I am working on Drupal 8 custom block. I want to print the site name in this custom block.
MyBlock.php
public function build() {
  return [
    '#markup' =&gt; t('This is a simple block!'),
  ];
}

How can I get the site name?
Get the site name from config and add the config as cacheable dependency so that the block gets updated when you change the site name.
public function build() {
  $config = \Drupal::config('system.site');

  $build = [
    '#markup' =&gt; $config-&gt;get('name'),
  ];

  $renderer = \Drupal::service('renderer');
  $renderer-&gt;addCacheableDependency($build, $config);

  return $build;
}