23.02.2015 Views

www.it-ebooks.info

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

[ 43 ]<br />

Chapter 2<br />

Views<br />

The view layer is one of the areas where Magento truly sets <strong>it</strong>self apart from other<br />

MVC applications. Unlike trad<strong>it</strong>ional MVC systems, Magento's view layer is divided<br />

into the following three different components:<br />

• Layouts: Layouts are XML files that define the block structure and properties<br />

such as name and the template file we can use. Each Magento module has <strong>it</strong>s<br />

own set of layout files.<br />

• Blocks: Blocks are used in Magento to reduce the burden on the controller by<br />

moving most of the logic into blocks.<br />

• Templates: Templates are PHTML files that contain the required HTML code<br />

and PHP tags.<br />

Layouts give the Magento frontend an amazing amount of flexibil<strong>it</strong>y. Each module<br />

has <strong>it</strong>s own layout XML files, which tell Magento what to include and render on<br />

each page request. Through the use of the layouts, we can move, add, or remove<br />

blocks from our store w<strong>it</strong>hout worrying about changing anything else other than<br />

our XML files.<br />

Dissecting a layout file<br />

Let's examine one of the core layout files of Magento, in this case catalog.xml:<br />

<br />

<br />

<br />

<br />

<br />

images/media/col_left_callout.jpg<br />

<br />

Our customer service is available 24/7.<br />

Call us at (555) 555-0123.<br />

<br />

checkout/cart<br />

<br />

<br />

<br />

<br />

<br />

<strong>www</strong>.<strong>it</strong>-<strong>ebooks</strong>.<strong>info</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!