How To Use Layouts

Prerequisities

You need to have your own module created and also controller, if you don’t know how to create module, just follow this tutorial first. If you was to refresh how to create Controller follow this guide. In this tutorial we assume that our namespace is Lukas and module name is Test capitalized, which means I will always have to write them capitalized in every XML files.

Registering new layout

Register new layout in your module’s /etc/config.xml file. Add this node as a child of <frontend> tag

<layout>
  <updates>
    <Test>
      <file>mylayout.xml</file>
    </Test>
  </updates>
</layout>

My final config.xml looks as follow

<config>
    <modules>
        <Lukas_Test>
            <version>0.0.1</version>
        </Lukas_Test>
    </modules>
    <frontend>
        <layout>
           <updates>
                <Test>
                    <file>mylayout.xml</file>
                </Test>
            </updates>
        </layout>
    <frontend>
</config>

Create new layout file

We named our new layout as mylayout.xml so we need to create that file now. By default your main theme is set up to rwd/default unless you changed it in admin panel.

Create new layout in your theme directory -> app/design/frontend/rwd/default/layout/mylayout.xml

write this code into it

<layout>
  <default>
    <remove name="header">
  </default>
</layout>

This will remove header from every single frontend page.

 


Lukas
Lukas Stranovsky
I am the guy who made this. Sorry for typos.