0

I have some simple template suggestions setup in my THEME_preprocess_node() function. Example:

function my_theme_preprocess_node(&$vars) {
  if ($vars['node']->type == 'MY_TYPE' && $vars['view_mode'] == 'MY_VIEW_MODE') {
    $vars['theme_hook_suggestions'][] = 'my__template';
  }
}

Then I have the template file (named my--template.tpl.php) setup in my theme. I cleared the cache, and this is recognized right away and works fine.

Then, after about an hour, if I refresh the page that uses the template, it suddenly is not recognized anymore. I clear cache again and it comes back.

Has anyone experienced this before?

Just FYI, I am using hook_theme() in a custom module to specify the theme for this page based on the URL alias.

4
  • Do you maybe use themekey, admin_theme or some other theme handler module?
    – leymannx
    Commented Mar 26, 2019 at 18:14
  • @leymannx No, it's a custom module only handling theme switching. However, I think I have found the issue. I specified the wrong hook name! I had other_theme_preprocess_node instead of my_theme_preprocess_node. I copied the hook from another theme and forgot to change the base. What a rookie move.
    – Micah
    Commented Mar 26, 2019 at 18:17
  • Just going to wait another hour or so to make sure that was it. Thanks for your response!
    – Micah
    Commented Mar 26, 2019 at 18:17
  • @leymannx Seems to have done the trick. Thanks again for jumping in.
    – Micah
    Commented Mar 26, 2019 at 18:58

1 Answer 1

0

Turns out I had the wrong hook specified. I copied this from another theme and forgot to update the hook prefix. So I had:

other_theme_preprocess_node

instead of:

my_theme_preprocess_node

Changing that seems to have resolved the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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