V
V
Vlad1712015-10-31 14:17:21
Drupal
Vlad171, 2015-10-31 14:17:21

How to override page template for specific content type in Drupal 8?

In Drupal 7 this was done in template.tpl.php:

function yourthemename_preprocess_page(&$vars) { 
   if (isset($vars['node']->type)) { 
      $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type; }
 }

Next, you could define a template . I don’t understand how to do this in Drupal 8. Can anyone help?
page--<node_type>.tpl.php

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad171, 2015-11-16
@Vlad171

I am answering my previous questions.
In the theme_get_suggestions hook we write the following:

if ($node = \Drupal::routeMatch()->getParameter('node')) { 
  	$suggestions[] = $prefix . $delimiter . $node->getType(); 
  }

All this disgrace must be written in a separately created module, or (which cannot be done at all) be added to core/includes/theme.inc in the theme_get_suggestions function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question