Debugging Tips: Filename cannot be empty

November 21, 2014  |  No Comments  |  by Raj (MagePsycho)  |  Latest, Magento

Problem

You may have seen this kind of error frequently logged in your Magento log file var/log/system.log:

Warning: include(): Filename cannot be empty in /app/code/core/Mage/Core/Block/Template.php on line xxx

This error means Magento is trying to include a template block with an empty string set as it’s template.

Solution

In order to find which template file is missing, simply edit the code in Mage_Core_Block_Template::fetchView() as:

public function fetchView($fileName)
{
    ...
    try {
        $includeFilePath = realpath($this->_viewDir . DS . $fileName);
        if (strpos($includeFilePath, realpath($this->_viewDir)) === 0 || $this->_getAllowSymlinks()) {
            /* edit - start */
            if (!is_file($includeFilePath)) {
                Mage::log($fileName, null, 'missing-phtml.log', true);
            }
            /* edit - end */
            include $includeFilePath;
        } else {
            Mage::log('Not valid template file:'.$fileName, Zend_Log::CRIT, null, null, true);
        }

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

You will see the missing .phtml filenames being logged. And search for that name in your layout xmls which will show you where it went wrong.
Happy Debugging!