Skip to main content
deleted 2 characters in body
Source Link
emy
  • 101
  • 3

I'm using Drupal 8, this worked for me.

In /core/modules/views/views.theme.inc file I appended following code intoto template_preprocess_views_view method:

$view = $variables['view'];
$id = $view->storage->id();

...
...
...

if( $id == '__VIEW_ID__' && $view->args[0]) {

    // Get tid from contextual argument of the view
    $tid = $view->args[0];

    // Load the Term Entity
    $term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($tid);
    // $term = Term::load($tid);

    // Term Title
    $new_title = $term->getName();

    // Set the new Page Title
    $request = \Drupal::request();
    if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) {
      $route->setDefault('_title', $new_title);
    }
 }

I'm using Drupal 8, this worked for me.

In /core/modules/views/views.theme.inc file I appended following code into template_preprocess_views_view method:

$view = $variables['view'];
$id = $view->storage->id();

...
...
...

if( $id == '__VIEW_ID__' && $view->args[0]) {

    // Get tid from contextual argument of the view
    $tid = $view->args[0];

    // Load the Term Entity
    $term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($tid);
    // $term = Term::load($tid);

    // Term Title
    $new_title = $term->getName();

    // Set the new Page Title
    $request = \Drupal::request();
    if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) {
      $route->setDefault('_title', $new_title);
    }
 }

I'm using Drupal 8, this worked for me.

In /core/modules/views/views.theme.inc file I appended following code to template_preprocess_views_view method:

$view = $variables['view'];
$id = $view->storage->id();

...
...
...

if( $id == '__VIEW_ID__' && $view->args[0]) {

    // Get tid from contextual argument of the view
    $tid = $view->args[0];

    // Load the Term Entity
    $term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($tid);
    // $term = Term::load($tid);

    // Term Title
    $new_title = $term->getName();

    // Set the new Page Title
    $request = \Drupal::request();
    if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) {
      $route->setDefault('_title', $new_title);
    }
 }
Source Link
emy
  • 101
  • 3

I'm using Drupal 8, this worked for me.

In /core/modules/views/views.theme.inc file I appended following code into template_preprocess_views_view method:

$view = $variables['view'];
$id = $view->storage->id();

...
...
...

if( $id == '__VIEW_ID__' && $view->args[0]) {

    // Get tid from contextual argument of the view
    $tid = $view->args[0];

    // Load the Term Entity
    $term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($tid);
    // $term = Term::load($tid);

    // Term Title
    $new_title = $term->getName();

    // Set the new Page Title
    $request = \Drupal::request();
    if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) {
      $route->setDefault('_title', $new_title);
    }
 }