2. What is rendering ? We understand rendering as a process of generating output for the customer. Client Server Web GET index.php HTTP/1.1 Host: somehos.com HTTP/1.1 200 OK ... <html> <head> ...
3. Two goals of rendering output in web Generate headers Generate response body How it works in magento ? Front (Mage_Core_Controller_Varien_Front::dispatch) contoller calls $response->sendResponse() Response object ( Mage_Core_Controller_Response_Http which extends Zend_Controller_Response_Http ) calls sendHeaders and outputBody So, the main goal of rendering system is to generate html body and assign it to response object body variable
5. Template and layout configuration files organization app design area (adminhtml or frontend) package (default, enterprise) theme (default, mytheme) layout template cage.xml, catalog.xml, etc.. template files (.phtml)
6. Generating output flow Controller sets body directly to response object. Example: Mage_Adminhtml_CustomerController::ordersAction public function ordersAction() { $this->_initCustomer(); $this->getResponse()->setBody( $this->getLayout() ->createBlock('adminhtml/customer_edit_tab_orders') ->toHtml() ); } Controller calls loadLayout(), renderLayout() Most of controllers follows this way. For example Mage_Adminhtml_Catalog_ProductController::indexAction public function indexAction() { $this->_title($this->__('Catalog')) ->_title($this->__('Manage Products')); $this->loadLayout(); $this->_setActiveMenu('catalog/products'); $this->renderLayout(); }
12. Looking for template file 1) In current theme (store config: default/design/theme/template ) 2) In fallback theme (store config: default/design/theme/default ) 3) In “ default ” theme 4) In “ base ” package “ default ” theme First of all package established (store config: default/design/package ) Then template file is searching in the following places:
14. Corollary Template execution is direct include inside Block_Template fetchView method. It means that “ $this ” inside template refers to correspondent block instance Each template file has own block instance which extends Mage_Core_Block_Template class. Magento (almost) never renders children of the block. Exception is Mage_Core_Block_Text_List class. There are 4 places where real template file could be located ( current theme, fallback theme, default theme, base package default theme ). Moreover if two appropriate file exists, first from the above list will be taken, which gives flexibility in overriding native templates.