Certificated magento

3.15) Is it possible to render a template without a block in Magento?

Well, never knows what’s the correct answer to some like this. This is not possible in a non-tricky way, but you may copy part of the fetchView() to make it works… Definitely not a good practise, but possible any way.

The include of a template in a Magento Block is as follows:

Mage_Core_Block_Template->fetchView()

public function fetchView($fileName)

{

    . . .

 

    // Templates can be output directly to the browser or its content added to

    // the response which at the end of the process is sent to the browser

    // in one piece. In most cases, it will be stored in the response and

    // Magento will send it at the end of the request processing

    $do = $this->getDirectOutput();

    if (!$do) {

        ob_start();

    }

 

    . . .

 

    // This part includes the template file directly, so it's result is output 

    // directly or captured to a variable (see ob_start and ob_get_clean calls)

    // The template file path is generated by realpath...

    $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);

    }

      

    . . .

 

    // Finally the generated output by the template, is captured or output.

    if (!$do) {

        $html = ob_get_clean();

    } else {

        $html = '';

    }

    . . .

}

0 Bình luận

Trở về
  • 1.12) Set up a cron job
  • 1.12) Set up a cron job

    Let’s start with server setup.   As any complex system, Magento has a lot of tasks that need to be executed...