SlideShare a Scribd company logo
Magento rendering system Vitaliy Golomoziy Consultant Magento Inc.
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> ...
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
Actors (Magento View Level)
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)
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(); }
Loading layout
Layout configuration file structure Layout configuration is an xml file. Root node is -  <layout> First-level node is arbitrary node which named “ handle ” Second-level node is  <block>  or  <reference> Block  attributes: name, type, output, template, as, translate Reference  attributes: name Block  children: block or action Action  attributes: method, ifconfig, block Action  children: any flat node. Action  children attribute: helper Reference  children: block, action
Layout configuration file example <layout version=&quot;0.1.0&quot;> <default translate=&quot;label&quot; module=&quot;page&quot;> <label>All Pages</label> <block type=&quot;page/html&quot; name=&quot;root&quot; output=&quot;toHtml&quot; template=&quot;page/3columns.phtml&quot;> <block type=&quot;page/html_head&quot; name=&quot;head&quot; as=&quot;head&quot;> <action method=&quot;addJs&quot;><script>prototype/prototype.js</script></action> <action method=&quot;addJs&quot; ifconfig=&quot;dev/js/deprecation&quot;>  <script>prototype/deprecation.js</script></action>   <action method=&quot;addJs&quot;><script>lib/ccard.js</script></action> ........................... </default>
Building layout example <block name=”root”> <block name=”head”> <action method=”doSomething> <some>_VALUE_</some> </action> </block> <block name=”header”> </block> <block name=”content”> ..... <block name=”somebock” type=”A”> .... </block> </block> </block> <block name=”root”> <block name=”head”> <action method=”doSomething”> <some>_VALUE_</some> </action> </block> <block name=”header”> </block> <block name=”content”> ..... </block> </block> <reference name=”content”> <block name=”somebock” type=”A”> .... </block> </reference> default FullActionName  catalog_product_view $root = new Block(); $head = new Block(); $head ->doSomething(_VALUE_); $root ->addChild($head); $header = new Block(); $content = new Block(); $someblock = new A(); $content ->addChild($someblock);
Render layout schema
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:
Block_Template fetchView method $do = $this->getDirectOutput(); if (!$do) { ob_start(); } if ( $this->getShowTemplateHints() ) { ... } try { $includeFilePath = realpath($this->_viewDir . DS . $fileName); if (strpos($includeFilePath, realpath($this->_viewDir)) === 0) { include $includeFilePath; } else { Mage::log('Not valid template file:'.$fileName, Zend_Log::CRIT, null, null, true); } } catch (Exception $e) { ob_get_clean(); throw $e; } if ($this->getShowTemplateHints()) { echo '</div>'; } if (!$do) { $html = ob_get_clean(); } else { $html = ''; } ....
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.
Root template example <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;> <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;<?php echo $this->getLang() ?>&quot; lang=&quot;<?php echo $this->getLang() ?>&quot;> <head> <?php echo $this->getChildHtml('head') ?> </head> <body<?php echo $this->getBodyClass()?' class=&quot;'.$this->getBodyClass().'&quot;':'' ?>> <?php echo $this->getChildHtml('after_body_start') ?> <div class=&quot;wrapper&quot;> <?php echo $this->getChildHtml('global_notices') ?> <div class=&quot;page&quot;> <?php echo $this->getChildHtml('header') ?> <div class=&quot;main-container col3-layout&quot;> <div class=&quot;main&quot;> <?php echo $this->getChildHtml('breadcrumbs') ?> <div class=&quot;col-wrapper&quot;> <div class=&quot;col-main&quot;> <?php echo $this->getChildHtml('global_messages') ?> <?php echo $this->getChildHtml('content') ?> </div> <div class=&quot;col-left sidebar&quot;> <?php echo $this->getChildHtml('left') ?> </div> </div> <div class=&quot;col-right sidebar&quot;> <?php echo $this->getChildHtml('right') ?> </div> </div> </div> <?php echo $this->getChildHtml('footer') ?> <?php echo $this->getChildHtml('before_body_end') ?> </div> </div> <?php echo $this->getAbsoluteFooter() ?> </body> </html> app/desig/frontend/base/default/template/page/3columns.phtml
Other ways for rendering children Extend your block from Mage_Core_Block_Text_List. class  Mage_Core_Block_Text_List  extends Mage_Core_Block_Text { protected function _toHtml() { $this->setText(''); foreach ($this->getSortedChildren() as $name) { $block = $this->getLayout()->getBlock($name); if (!$block) { Mage::throwException(Mage::helper('core')->__('Invalid block: %s', $name)); } $this->addText($block->toHtml()); } return parent::_toHtml(); } } Call  getChildHtml('')  without parameters. public function getChildHtml($name='', $useCache=true, $sorted=false) { if ('' === $name) { ... foreach ($children as $child) { $out .= $this->_getChildHtml($child->getBlockAlias(), $useCache);   } return $out; } else { ... }
The End

More Related Content

PDF
Doctrine 2
PDF
購物車程式架構簡介
PDF
Advanced php testing in action
PDF
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
PPTX
Using of TDD practices for Magento
PPTX
Optimizing Magento by Preloading Data
PDF
international PHP2011_Bastian Feder_jQuery's Secrets
PDF
Php unit the-mostunknownparts
Doctrine 2
購物車程式架構簡介
Advanced php testing in action
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Using of TDD practices for Magento
Optimizing Magento by Preloading Data
international PHP2011_Bastian Feder_jQuery's Secrets
Php unit the-mostunknownparts

What's hot (20)

PDF
Design Patterns in PHP5
PPTX
JQuery Presentation
PDF
PHP Data Objects
PPT
Framework
PPTX
Adding Dependency Injection to Legacy Applications
PDF
Drupal 8: Forms
PDF
Business Rules with Brick
KEY
Php 101: PDO
PDF
Caching and Scaling WordPress using Fragment Caching
PDF
Design Patterns avec PHP 5.3, Symfony et Pimple
PDF
Min-Maxing Software Costs - Laracon EU 2015
PDF
jQuery secrets
PDF
CGI::Prototype (NPW 2006)
KEY
Unit testing with zend framework PHPBenelux
PDF
PHPUnit Episode iv.iii: Return of the tests
PDF
The IoC Hydra - Dutch PHP Conference 2016
PDF
Min-Maxing Software Costs
PDF
50 Laravel Tricks in 50 Minutes
KEY
Symfony2 Building on Alpha / Beta technology
PDF
Agile database access with CakePHP 3
Design Patterns in PHP5
JQuery Presentation
PHP Data Objects
Framework
Adding Dependency Injection to Legacy Applications
Drupal 8: Forms
Business Rules with Brick
Php 101: PDO
Caching and Scaling WordPress using Fragment Caching
Design Patterns avec PHP 5.3, Symfony et Pimple
Min-Maxing Software Costs - Laracon EU 2015
jQuery secrets
CGI::Prototype (NPW 2006)
Unit testing with zend framework PHPBenelux
PHPUnit Episode iv.iii: Return of the tests
The IoC Hydra - Dutch PHP Conference 2016
Min-Maxing Software Costs
50 Laravel Tricks in 50 Minutes
Symfony2 Building on Alpha / Beta technology
Agile database access with CakePHP 3
Ad

Viewers also liked (17)

PPTX
1000 миллисекунд из жизни Magento
PPTX
Все дороги ведут в Checkout
PPTX
Индексирование в Magento
PPTX
Применение компонент-ориентированной архитектуры для написания Magento Extens...
PDF
NoSQL и Zend Framework (Никита Грошин)
PDF
Эволюция ZF: архитектура, шаблоны, рефакторинг
PDF
Встречайте Zend Framework 2.0
PDF
Хранение, обработка и отдача статики с использованием \Zend\File. Опыт социал...
PPTX
Реализация шаблонов корпоративных приложений в Magento
PDF
Применение Scrum и Kanban для разработки web-приложений
ODP
Мобильные клиенты интернет-магазинов
PPT
Юнит тестирование в Zend Framework 2.0
PPTX
Преимущества использования полнотекстового поиска в интернет-магазинах
PPTX
Ключ успеха – процесс или продукт?
PPT
Управление продуктом в стиле Magento Unified Process
PPTX
Применение TDD при разработке веб-сервисов
PDF
NoSQL и Zend Framework (Ростислав Михайлив)
1000 миллисекунд из жизни Magento
Все дороги ведут в Checkout
Индексирование в Magento
Применение компонент-ориентированной архитектуры для написания Magento Extens...
NoSQL и Zend Framework (Никита Грошин)
Эволюция ZF: архитектура, шаблоны, рефакторинг
Встречайте Zend Framework 2.0
Хранение, обработка и отдача статики с использованием \Zend\File. Опыт социал...
Реализация шаблонов корпоративных приложений в Magento
Применение Scrum и Kanban для разработки web-приложений
Мобильные клиенты интернет-магазинов
Юнит тестирование в Zend Framework 2.0
Преимущества использования полнотекстового поиска в интернет-магазинах
Ключ успеха – процесс или продукт?
Управление продуктом в стиле Magento Unified Process
Применение TDD при разработке веб-сервисов
NoSQL и Zend Framework (Ростислав Михайлив)
Ad

Similar to Система рендеринга в Magento (20)

PPTX
Finding Your Way: Understanding Magento Code
PDF
Magento2 Basics for Frontend Development
PPTX
Magento 2.0: Prepare yourself for a new way of module development
PPTX
Magento mega menu extension
PPTX
Magento 2 theming - knowledge sharing session by suman kc
PDF
How To Create Theme in Magento 2 - Part 1
PDF
Designing for magento
PPTX
Magento2 frontend development
PDF
Fronted From Scratch - Supercharge Magento page speed
PDF
Front End Development in Magento
PPT
Introduction to Mangento
PPT
Mangento
PPT
Render API - Pavel Makhrinsky
PDF
Magento 2 Backend Development Essentials
PPTX
Magento 2 View Layer Evolution
PPT
Mageguru - magento custom module development
PDF
Art blue responsive mangeto theme document
PDF
Introduction to the Magento eCommerce Platform
PPT
Magento 20110406
PDF
How to-create-a-simple-module-in-magento-2.0
Finding Your Way: Understanding Magento Code
Magento2 Basics for Frontend Development
Magento 2.0: Prepare yourself for a new way of module development
Magento mega menu extension
Magento 2 theming - knowledge sharing session by suman kc
How To Create Theme in Magento 2 - Part 1
Designing for magento
Magento2 frontend development
Fronted From Scratch - Supercharge Magento page speed
Front End Development in Magento
Introduction to Mangento
Mangento
Render API - Pavel Makhrinsky
Magento 2 Backend Development Essentials
Magento 2 View Layer Evolution
Mageguru - magento custom module development
Art blue responsive mangeto theme document
Introduction to the Magento eCommerce Platform
Magento 20110406
How to-create-a-simple-module-in-magento-2.0

More from Magecom Ukraine (9)

PPTX
10 000 вёдер или в погоне за Ключом от всех дверей
PPTX
Flexibility vs Conformity - lessons learned in Open Source
PDF
Современные платформы (фреймворки) разработки веб- приложений на PHP
PPTX
Деплоймент и распространение обновлений для веб-приложений
PPTX
Расширение функциональности модульного MVC приложения
PDF
Тестирование Magento с использованием Selenium
PPTX
Архитектура веб-приложений на примере Zend Framework и Magento
PPTX
Extension Marketplace. Площадки для распространения ПО
PPT
Стандарты и соглашения в сложных ООП-приложениях
10 000 вёдер или в погоне за Ключом от всех дверей
Flexibility vs Conformity - lessons learned in Open Source
Современные платформы (фреймворки) разработки веб- приложений на PHP
Деплоймент и распространение обновлений для веб-приложений
Расширение функциональности модульного MVC приложения
Тестирование Magento с использованием Selenium
Архитектура веб-приложений на примере Zend Framework и Magento
Extension Marketplace. Площадки для распространения ПО
Стандарты и соглашения в сложных ООП-приложениях

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Electronic commerce courselecture one. Pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
KodekX | Application Modernization Development
PPT
Teaching material agriculture food technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Approach and Philosophy of On baking technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation_ Review paper, used for researhc scholars
Electronic commerce courselecture one. Pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Understanding_Digital_Forensics_Presentation.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
20250228 LYD VKU AI Blended-Learning.pptx
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
Unlocking AI with Model Context Protocol (MCP)
KodekX | Application Modernization Development
Teaching material agriculture food technology
The AUB Centre for AI in Media Proposal.docx
Spectroscopy.pptx food analysis technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
Approach and Philosophy of On baking technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf

Система рендеринга в Magento

  • 1. Magento rendering system Vitaliy Golomoziy Consultant Magento Inc.
  • 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(); }
  • 8. Layout configuration file structure Layout configuration is an xml file. Root node is - <layout> First-level node is arbitrary node which named “ handle ” Second-level node is <block> or <reference> Block attributes: name, type, output, template, as, translate Reference attributes: name Block children: block or action Action attributes: method, ifconfig, block Action children: any flat node. Action children attribute: helper Reference children: block, action
  • 9. Layout configuration file example <layout version=&quot;0.1.0&quot;> <default translate=&quot;label&quot; module=&quot;page&quot;> <label>All Pages</label> <block type=&quot;page/html&quot; name=&quot;root&quot; output=&quot;toHtml&quot; template=&quot;page/3columns.phtml&quot;> <block type=&quot;page/html_head&quot; name=&quot;head&quot; as=&quot;head&quot;> <action method=&quot;addJs&quot;><script>prototype/prototype.js</script></action> <action method=&quot;addJs&quot; ifconfig=&quot;dev/js/deprecation&quot;> <script>prototype/deprecation.js</script></action> <action method=&quot;addJs&quot;><script>lib/ccard.js</script></action> ........................... </default>
  • 10. Building layout example <block name=”root”> <block name=”head”> <action method=”doSomething> <some>_VALUE_</some> </action> </block> <block name=”header”> </block> <block name=”content”> ..... <block name=”somebock” type=”A”> .... </block> </block> </block> <block name=”root”> <block name=”head”> <action method=”doSomething”> <some>_VALUE_</some> </action> </block> <block name=”header”> </block> <block name=”content”> ..... </block> </block> <reference name=”content”> <block name=”somebock” type=”A”> .... </block> </reference> default FullActionName catalog_product_view $root = new Block(); $head = new Block(); $head ->doSomething(_VALUE_); $root ->addChild($head); $header = new Block(); $content = new Block(); $someblock = new A(); $content ->addChild($someblock);
  • 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:
  • 13. Block_Template fetchView method $do = $this->getDirectOutput(); if (!$do) { ob_start(); } if ( $this->getShowTemplateHints() ) { ... } try { $includeFilePath = realpath($this->_viewDir . DS . $fileName); if (strpos($includeFilePath, realpath($this->_viewDir)) === 0) { include $includeFilePath; } else { Mage::log('Not valid template file:'.$fileName, Zend_Log::CRIT, null, null, true); } } catch (Exception $e) { ob_get_clean(); throw $e; } if ($this->getShowTemplateHints()) { echo '</div>'; } if (!$do) { $html = ob_get_clean(); } else { $html = ''; } ....
  • 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.
  • 15. Root template example <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;> <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;<?php echo $this->getLang() ?>&quot; lang=&quot;<?php echo $this->getLang() ?>&quot;> <head> <?php echo $this->getChildHtml('head') ?> </head> <body<?php echo $this->getBodyClass()?' class=&quot;'.$this->getBodyClass().'&quot;':'' ?>> <?php echo $this->getChildHtml('after_body_start') ?> <div class=&quot;wrapper&quot;> <?php echo $this->getChildHtml('global_notices') ?> <div class=&quot;page&quot;> <?php echo $this->getChildHtml('header') ?> <div class=&quot;main-container col3-layout&quot;> <div class=&quot;main&quot;> <?php echo $this->getChildHtml('breadcrumbs') ?> <div class=&quot;col-wrapper&quot;> <div class=&quot;col-main&quot;> <?php echo $this->getChildHtml('global_messages') ?> <?php echo $this->getChildHtml('content') ?> </div> <div class=&quot;col-left sidebar&quot;> <?php echo $this->getChildHtml('left') ?> </div> </div> <div class=&quot;col-right sidebar&quot;> <?php echo $this->getChildHtml('right') ?> </div> </div> </div> <?php echo $this->getChildHtml('footer') ?> <?php echo $this->getChildHtml('before_body_end') ?> </div> </div> <?php echo $this->getAbsoluteFooter() ?> </body> </html> app/desig/frontend/base/default/template/page/3columns.phtml
  • 16. Other ways for rendering children Extend your block from Mage_Core_Block_Text_List. class Mage_Core_Block_Text_List extends Mage_Core_Block_Text { protected function _toHtml() { $this->setText(''); foreach ($this->getSortedChildren() as $name) { $block = $this->getLayout()->getBlock($name); if (!$block) { Mage::throwException(Mage::helper('core')->__('Invalid block: %s', $name)); } $this->addText($block->toHtml()); } return parent::_toHtml(); } } Call getChildHtml('') without parameters. public function getChildHtml($name='', $useCache=true, $sorted=false) { if ('' === $name) { ... foreach ($children as $child) { $out .= $this->_getChildHtml($child->getBlockAlias(), $useCache); } return $out; } else { ... }