I have 2 routes

  path: '/math/one'
    _controller: '\Drupal\games\Controller\GamesController::one'
    _title: 'My Title'
    _permission: 'access content'

  path: '/math/two'
    _controller: '\Drupal\games\Controller\GamesController::two'
    _permission: 'access content'

Route games.one has _title and Route games.two does not have. Now the issue is When I access route game.two, It shows an empty div for title.

How to remove this empty div?

  • 1
    Better, you need show code class controller. What's code in controller GamesController::one – Jonh Feb 7 '17 at 9:57
  • 1
    edit the page.html.twig – user21641 Feb 7 '17 at 9:57
  • go to the block layout and change the visibility of the Page Title block to not show on /math/two – 4k4 Feb 7 '17 at 10:40

You can do this by overriding the page.html.twig for that page and stripping out the title.

To override the template for that specific page you should probably alter the hook suggestions:

 * Implements hook_theme_suggestions_HOOK_alter().
function THEME_NAME_theme_suggestions_page_alter(array &$suggestions, array $variables) {

  if ($node = \Drupal::routeMatch()->getRouteName() == 'games.two') {
    $suggestions[] = 'page__no_title';

Now you can copy the page.html.twig template to your theme folder, rename it to page--no-title.html.twig and strip out the title tag.

Hope this helps

  • I think have a lot of way do that. But if you want use preprocess better choose _preprocess_page_title() and set variable title to false. – Jonh Feb 7 '17 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.