5

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

5

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.

  • Sounds interesting. Thx. – snh_nl Feb 5 '16 at 20:30
4

We solved this by adding

    if (strpos($includeFilePath, realpath($this->_viewDir)) === 0 || $this->_getAllowSymlinks()) {
        if (empty($includeFilePath)) {
            Mage::Log("Cannot set emptt filename" . $fileName . " on a " . get_class($this) );
            Mage::log(Mage::printDebugBacktrace(), null, 'backtrace.log'); //or you can even log the backtrace
            include $includeFilePath;
        } else {
            include $includeFilePath;
        }
    } else {
        Mage::log('Not valid template file:'.$fileName, Zend_Log::CRIT, null, null, true);
    }

where 'Mage::printDebugBacktrace()' was grabbed from here

http://www.blog.magepsycho.com/utilizing-debug_backtrace-function-for-magento-debugging/

This way we had some more info to go by ...

  • 1
    update: use Varien_Debug::backtrace() – Aleksey Razbakov Aug 28 '15 at 13:01
  • I know this subject is quiet old but ... I tried this solution and it seems to generate a nice table containing a lot of valuable details .....unfortunately not for me :) What I suppose to do? check all those files manually if they exists ? – Rob D. A. Jun 27 '17 at 12:06
-1

In file app/code/core/Mage/Core/Block/Template.php in function fetchView() change

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

to

catch (Exception $e) {
            ob_get_clean();
            Mage::log($fileName, NULL, 'template.log', TRUE);
            throw $e;
        }

This will log the expected file which is missing.

  • This does not help if filename is empty – Kevin Krieger Feb 20 '18 at 9:45
  • @KevinKrieger Have you checked it? – Anshu Mishra Feb 20 '18 at 10:25
  • yes, I tried. If template file is empty then this solution does not work. – Kevin Krieger Feb 21 '18 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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