skounis / mt-countdown

Display a custom block with a Countdown function for Announcements, such as time-limited offers or upcoming releases in a Drupal 8 website. Drupal 8 module
0 stars 1 forks source link

Override the templates in the theme #30

Closed skounis closed 6 years ago

skounis commented 6 years ago

@a4dyakonov Could you please confirm that the template files, this module has, could be overridden if we use the same file names in the selected/active theme?

People here have reported that they tried that with no success.

a4dyakonov commented 6 years ago

@skounis Hi, Stavros. I'm sure that our module doesn't use common theme templates. It has only own template, the template for the block and separates HTML file which we inject into the main template using the hook.

skounis commented 6 years ago

@a4dyakonov So do we have the option to create our own mt_countdown_inject.html.twig in the folder of the active theme?

Will this override the the template file of the module?

Could you please confirm?

a4dyakonov commented 6 years ago

We can override the template of our module. It is mt_countdown.html.twig. But mt_countdown_inject.html.twig is not a template, it separates HTML file. We have to override it using the hook.

a4dyakonov commented 6 years ago

We should implement hook_page_attachments_alter().

skounis commented 6 years ago

Alex,

We should improve that, we should be able to override everything by using template files. Is that possible?

a4dyakonov commented 6 years ago

@skounis Then we will have what we had in the previous version. We must replace the main template with our template. But this is not exactly Drupal's way. Because we do not know what will happen if someone else redefines this template. We can not insert a template into another template without using a hook.

skounis commented 6 years ago

@a4dyakonov Could our code, in the module, checks the active theme for a template file with this name?

It is very crucial to allow the users to override our templates (HTML snippets) at the theme's level, by creating HTML/twig files.

a4dyakonov commented 6 years ago

@skounis I've Added ability checks the active theme of a template file with mt_countdown_inject.html.twig name. If it does not exist, we include our module file.

skounis commented 6 years ago

@a4dyakonov It looks fine. It is merged. We will test. Thank you