How to Move CMS Page Title Outside of Normal Layout in Magento 1.9

cmslayoutmagento-1.9page-layoutspage-title

I have a CMS page with the 1-column layout. I'd like to move the page title outside the main container of the page. The current setup is as follows:

<div class="main-container col1-layout">
       <div class="main">
         <div class="page-title">
           <h1>Page Title</h1>
         </div>
           <p>Some content here..</p>               
        </div>
       </div>
 </div>

I would like the page title element to sit outside the main container. Can this be done through an XML update?

Best Answer

You can't do this with a simple layout update xml. The easiest way to achieve this is create a new root template specific to your cms page. Steps for this is given below.

1. Layout Update XML File

Go to CMS > Pages > [Select your CMS Page] > Design > Layout Update XML section. Put this layout update code there.

<!-- removing default page heading block -->
<reference name="content">
    <remove name="page_content_heading" />
</reference>

<!-- defines new root template;add new page head block -->
<reference name="root">
    <action method="setTemplate">
        <template>custom/page/cms_1column.phtml</template>
    </action>
     <block type="core/template" name="cms_page_heading" as="cms_page_heading" template="cms/content_heading.phtml"/>
</reference>

This code basically performs 3 actions.

  1. It removes the default CMS Page heading block from layouts; So it will eventually removes the default title section that you are viewing in your cms page.

  2. It defines a new root template, custom/page/cms_1column.phtml for your CMS Page; I will explain why we need this.

  3. We are again redefining CMS Page heading block, but this time it comes inside root block and not inside content block.

2. Define Custom Root Template

Now create a new file app\design\frontend\[package]\[theme]\template\custom/page/cms_1column.phtml and copy paste all content of app\design\frontend\[package]\[theme]\template\page/1column.phtml to that file. Then call our heading block inside that file as like this.

<div class="wrapper">
    <?php echo $this->getChildHtml('global_notices') ?>
    <div class="page">
        <?php echo $this->getChildHtml('header') ?>
        <?php echo $this->getChildHtml('cms_page_heading') ?>
        <div class="main-container col1-layout">
            <div class="main">
                ...

As you can see <?php echo $this->getChildHtml('cms_page_heading') ?> this part renders the CMS Page heading block and it comes above layout-div block. You can adjust the position of your CMS page heading block according to your need as per your need.

We are using a new root template only for adding this custom CMS Page heading block. This will avoid touching of core files and hence would be the best solution in this case.

Related Topic