You are here

public function TwigExtension::drupalTitle in Twig Tweak 8

Same name and namespace in other branches
  1. 8.2 src/TwigExtension.php \Drupal\twig_tweak\TwigExtension::drupalTitle()

Returns a title for the current route.

Return value

array A render array to represent page title.

File

src/TwigExtension.php, line 363

Class

TwigExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\twig_tweak

Code

public function drupalTitle() {
  $title = \Drupal::service('title_resolver')
    ->getTitle(\Drupal::request(), \Drupal::routeMatch()
    ->getRouteObject());
  $build['#markup'] = render($title);
  $build['#cache']['contexts'] = [
    'url',
  ];
  return $build;
}