I've been trying to debug a weird bug on Drupal 7 for awhile. It happens randomly on my site as it's hard to reproduce. I'm able to finally get ddebug_backtrace() to run when the error happens. The error breaks all of my views on the site when it happens and throws the following error:

Warning: include(/home/xxx/public_html/.tpl.php): failed to open stream: No such file or directory in theme_render_template() (line 1534 of /home/xxx/public_html/includes/theme.inc).

It's complaining that theme_render_template() can't find a template file as the variable given to the function is just .tpl.php.

I'm able to insert an if statement when this happens within that function as this:

  if($template_file == '.tpl.php') {
    print_r('TEMPLATE FILE: ');

I'm able to get the debug output in krumo as shown below. I'm not exactly sure what I should be looking for. I just understand that each numbered line represents where that function was called within that order. But what I'm trying to look for is a blank variable of some sort which makes it output .tpl.php to give such an error.

Judging from the output, the culprit is the Views module, but I'm not sure where. What should I be looking for exactly?

enter image description here

  • Digging into the code, you're looking for the reason why the hook info array returned from the theme registry has an empty template key when the render function is invoked from theme(). Don't worry about theme_register_template(), that's irrelevant - it's just working with what it's given. Go to /devel/php, run dpm(theme_get_registry(FALSE));, and look for entries that match up with items in the args array to theme() (views_view etc). If any of those have an empty template, that's what's causing the problem
    – Clive
    May 13, 2016 at 19:57
  • thanks clive. just did a dpm(theme_get_registry(FALSE)); and it return an empty array on the dpm output: prntscr.com/b3pm2r May 13, 2016 at 20:18
  • Oh right it's not an array is it - try foreach (theme_get_registry(true) as $item) { if (isset($item['template']) && empty($item['template'])) { dpm($item); } }, that'll dump out any item that has a template key with an empty value
    – Clive
    May 13, 2016 at 20:25
  • Er no, wrong again, just try dpm(theme_get_registry(true));
    – Clive
    May 13, 2016 at 20:32
  • Ok i was able to get an output when set to true. It spit out a 562 element array and I clicked on each one then did a search for *0 characters to see if it highlighted anything on the page and it didnt. prntscr.com/b3rr5s --- i tried to just read the ddbacktrace() function, but I can't pinpoint when does it set the blank variable that causes it to output an empty .tpl.php. May 13, 2016 at 23:31

1 Answer 1


This bug was quite annoying to solve. What I did was:

  • Isolate the variable that was causing the issue.
  • Setup a conditional to detect this variable when it happens.
  • Add drupal's ddebug_backtrace() to the conditional.
  • Trace back to where the function was being called up.
  • Find out how that problematic variable is being passed in.
  • Keep following the backtrace to the point where that variable is assigned and not just passed along to another function. In my case it was in theme() that assigned the blank variable $template_file.
  • From there I needed to know when theme() was being called. The original backtrace didn't leave any clues to which module was calling it aside from views, but views gets called all over the place. Now I needed to find the module that was calling views.
  • In theme() there were a bunch of hook variables that gave the hint of where it was coming from. I dpm() all the $hook and $hooks variables and it showed the error was happening when a "display suite" hook was being called.
  • In the end all I needed to do was uncheck this box. I still don't know why it caused the issue randomly... -_-

enter image description here

My debug code to get the output I needed: enter image description here

  • Strange, I have that box checked on a website and it works flawless. It could have been your PHP ran out of memory (this is often a cause of strange and inconsistent behavior). You could try to increase the memory limit in your php.ini file and see if it still happens. On the other hand if you do not need the functions provided by the checkbox, leave it like this :) May 14, 2016 at 15:00
  • seems like its not that box after all. the errors came back after using the site for some time. I was able to debug it a bit further. It seems that the theme registry is missing the "views_view" array when this bug happens, but when it is working that array exists. I'm not sure where to look now. May 16, 2016 at 18:45

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.