LAYOUTS, BLOCKS AND TEMPLATES IN MAGENTO
16689
single,single-post,postid-16689,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-5.9,wpb-js-composer js-comp-ver-4.3.4,vc_responsive

LAYOUTS, BLOCKS AND TEMPLATES IN MAGENTO

structure-570x559

05 Aug LAYOUTS, BLOCKS AND TEMPLATES IN MAGENTO

LAYOUTS, BLOCKS AND TEMPLATES IN MAGENTO

The new developer working with magento often confused with system layout display. This article tells us that we connect with each other and we have a role in the MVC pattern.

In Magento, the floor View  covering with Block and Template. Block is the object PHP Template is also a combination of the code files html and php (ending phtml). Inside the template files using $this to reference the object to its block.

1. Block

Magento block divided into two categories:  structure block and  content block.

– Structural Block: These blocks are created for formatting position for the other blocks in a page. Take for example the homepage of the  magento default using three column layout:

  • Head
  • Left
  • Content
  • Right
  • Footer

structure-570x559

– Content Block: This is  the content block, they are displayed inside the structure  block. Each block content often display a certain content blocks through the template file and insert the father’s block structure trog block .. Be right column above image there are any blocks content:

  • Minicart
  • Recently viewed product
  • Newsletter subsription block
  • Poll

Upon receiving a request from a user 1 to show the first page:

– Magento loads structural areas

– Each of the structure of the content block. Magento will gather this block and assign the corresponding structure block to handle the output layout.

– Eventually the system will return the final results to the browser content was formatted location.

2. Template

Templates are files placed in the folder phtml design. They include php code and html code should have extension phtml. The template file works fetching data from file block and display.

File template Examples:

3. Layout

Through the first two we have to imagine what is block and template is, we have nothing but effects still have some issues that we do not know about them:

So you can imagine I’ll go easier on a specific example, there is action in “Hello World” to the browser.

Step 1: create 1 file layout with name local.xml

app/design/frontend/base/default/layout/local.xml

Step 2: Create file template simple_page.phtml

app/design/frontend/base/default/template/magentotutorial/helloworld/simple_page.phtml

 Step 3: In this final step will see fruition by creating an action in a controller and in which any two methods loadLayout call () and renderLayout ():

After finishing please clear  cache and refresh just write action to see results display.

In the article there are still many places lacking and looking forward to the feedback from all of you. :)

Hope this article will help you, thanks!

Jenny

 

 

Jenny Tran
hatran260612@gmail.com
No Comments

Post A Comment