2

I am using a custom module and using Bartik theme(from Drupal 8 core module) and hence need to define a content type specific template like node--[type].html.twig

I added hook_theme in my custom module as follows

function custom_autofill_reference_theme($existing, $type, $theme, $path){
   drupal_set_message($path);
   return [
    'node' => [
      'path' => $path . '/templates',
      'template' => 'node',
    ],
  ];
}

but not sure on how to add a content type specific template in a custom module without the need to create a custom theme?

  • You mean a content type specific template in a custom module without the need to create a custom theme? – 4k4 Oct 30 '18 at 19:10
  • yes @4k4, I found the solution , I will send an answer for the same. – harshal Oct 30 '18 at 19:25
5
/**
 * Implements hook_theme().
 */
function custom_theme() {
  return [
    'node__custom_content_type' => [
      'base hook' => 'node',
    ],
  ];
}

Then make sure that you have the content type template under custom/templates/node--custom-content-type.html.twig

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.