Magento – How to debug “empty template”: Filename cannot be empty in Template.php

debugdebuggingtemplate

we are suddenly seeing an empty template issue in our logs. And I am finding it difficult to debug which module/function is causing this.

Question: with what debug statement could I capture the culprit?

LOG

ERR (3): Warning: include(): Filename cannot be empty  in /app/code/core/Mage/Core/Block/Template.php on line 241
ERR (3): Warning: include(): Filename cannot be empty  in /app/code/core/Mage/Core/Block/Template.php on line 241
ERR (3): Warning: include(): Failed opening '' for inclusion (include_path='/lib/minify:/app/code/local:/app/code/community:/app/code/core:/lib:.')  in /app/code/core/Mage/Core/Block/Template.php on line 241

and the code in template.php

   try {
        $includeFilePath = realpath($this->_viewDir . DS . $fileName);
        if (strpos($includeFilePath, realpath($this->_viewDir)) === 0 || $this->_getAllowSymlinks()) {
            include $includeFilePath;
        } else {
            Mage::log('Not valid template file:'.$fileName, Zend_Log::CRIT, null, null, true);
        }

    } catch (Exception $e) {
        ob_get_clean();
        throw $e;
    }

help appreciated ;P

Best Answer

I have the same problem once in a while, the problem is always a missing template file. Unfortunately the error messsage with its printed stack trace does not reveal much, so you don't know which template file actually is missing.

If you use XDebug, you can set a conditional breakpoint at /app/code/core/Mage/Core/Block/Template.php line 241 with the condition $includeFilePath=='' and then when it halts, inspect the $filename variable to see which file should be included. Looking at the variables in the call stack will show you more information about the block and where it is in the layout.

However, this is still annoying, so I started to write a developer module for more meaningful error messages: https://github.com/schmengler/DebugErrors "Filename cannot be empty" is the first error it covers.

Related Topic