0
votes

I am building a simple module with features in drupal 8. Basically it is just a content-type with some fields exported with the features module. now i am trying to store a template for this content type IN my costume module to make the module reusable in other projects. All in all: i want to store the template for my content type in the module and not in the theme. (in an own templates/ directory)

In Drupal 7 the approach was made with something like this:

function mymodule_theme($existing, $type, $theme, $path) {
  return array(
  'node__mycontenttypemachinename' => array(
      'render element' => 'elements',
      'template' => 'node--mycontenttypemachinename', //removed the "templates/"
      'base hook' => 'node' //this line did the job
    )
  );
}

i found this post on the drupal site, but i am not sure if it is the correct way to reach what i want. and if it is the way (i tried this of course), can someone explain how to get it work. i have some issues with this part:

Step #2: Call the Template In the place where you are returning your render array (whether from a controller method that is called from your router yml file, or wherever), make a call to your twig template.

help would be appreciated.

EDIT: I tried the Drupal 7 way. Drupal recognices the template, in the twig-debug I can see it is using my template. Problem: I can enter some HTML there; but if I try to use this for example: {{ content }} I see nothing. In my theme´s template-folder this is working. any ideas?

EDIT 2: I added the missing line in my code-example above. For everyone how wants to reach the same like me.

solved

1

1 Answers

2
votes

I will answer this myself.

I was missing the base hook for theming.

'base hook' => 'node'

I edited the example code in my question for everybody who has the same issue.