Using Layout XML to Customize a Magento Theme

Jan 11, 2018342Sergey Samets
Using Layout XML to Customize a Magento Theme

The article is dedicated to some questions from Magento 1 front end developer certification. The FAQs are written in a simple and clear way by the developers who have already passed the exam. Hope it’ll help you improve your skills and solidify your knowledge.

Understanding processing order of layout handles and other directives

Using XML, you’re able to perform any action: add, remove and modify blocks. But first, it’s necessary to know the structural blocks that are commonly used. These are header, left, content, right, footer. At the same time, you need to be good at layout handles the structure of which looks as follows: [module_front_name]_[controller_name]_[action_name], that means if we want to add a block on the main page, we will have to include cms_index_index too.
Let’s have a closer look at the example how to add a block via XML on the main page. XML will be like that:

If we want to remove a block with a banner, so the code will be as follows:

Specify the root template for all pages or for a specific page

In order to specify the root template for all pages, we need to open XML pages, for example, page.xml and add in <default>:

If you want to specify the root template for a specific page, it’s necessary to write its handles by type [module_front_name]_[controller_name]_[action_name], for example, the contact page:

Assign a customized template file using layout XML

Here we need to use the setTemplate method. Let’s consider the following example. In order to use a customized template on the product page view-custom.phtml located in the folder with a pathway /template/catalog/product/view-custom.phtml, we can add the following lines into local.xml files of our theme:



Post a new comment

top
BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *