0
votes

I'm hoping someone can help me with this. I've been trying to add a custom template to the list of available layouts when adding a CMS page to magento. I've followed this tutorial.

However, my custom template is not showing in the list of available layouts. I have been able to do this successfully by hacking the magneto core file as described at the end of that article, but would prefer to do it as a module.

I have created the following files

app/code/local/mycustom/template/config.xml

<?xml version="1.0"?>
<config>
    <modules>
       <mycustom_template>
           <version>0.1.0</version>
       </mycustom_template>
    </modules>
    <global>
       <page>
          <layouts>
            <home translate="label">
               <label>Home Page</label>
               <template>page/home.phtml</template>
               <layout_handle>custom_homepage</layout_handle>
            </home>
          </layouts>
        </page>
    </global>
</config>

and app/etc/modules/mycustom_template.xml

<?xml version="1.0"?>
<config>
  <modules>
    <mycustom_template>
      <active>true</active>
      <codePool>local</codePool>
      <depends>
        <Mage_Page />
      </depends>
    </mycustom_template>
  </modules>
</config>
2
try this link - Zaheerabbas
That link says to do exactly what I'm doing. It also references the same wiki page I followed initially. Doesn't seem to work. - khaos337
I just figured out the problem. In Magento all your namespace and module names must have the first letter uppercase. Simply changing this naming convention to Mycustom_Template made all the difference! - khaos337

2 Answers

1
votes

Create the file app/etc/modules/Easylife_Layout.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Layout>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Page />
            </depends>
        </Easylife_Layout>
    </modules>
</config>

also create app/code/local/Easylife/Layout/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Layout>
            <version>0.0.1</version>
        </Easylife_Layout>
    </modules>
    <global>
        <page>
            <layouts>
                <custom_layout module="page" translate="label">
                    <label>Custom layout</label>
                    <template>page/custom_layout.phtml</template>
                    <layout_handle>custom_layout</layout_handle>
                </custom_layout>
            </layouts>
        </page>
    </global>
    <frontend>
        <layout>
            <updates>
                <easylife_layout>
                    <file>easylife_layout.xml</file>
                </easylife_layout>
            </updates>
        </layout>
    </frontend>
</config>

create app/design/frontend/your package/yourtheme/layout/easylife_layout.xml

<?xml version="1.0"?>
<layout>
    <custom_layout translate="label">
        <label>Custom layout</label>
        <reference name="root">
            <action method="setTemplate"><template>page/custom_layout.phtml</template></action>
            <action method="setIsHandle"><applied>1</applied></action>
        </reference>
    </custom_layout>
</layout>

and finally create app/design/frontend/your package/yourtheme/template/page/custom_layout.phtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
<head>
<?php echo $this->getChildHtml('head') ?>
</head>
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
<?php echo $this->getChildHtml('after_body_start') ?>
<div class="wrapper custom-layout">
    <?php echo $this->getChildHtml('global_notices') ?>
    <div class="page">
        <?php echo $this->getChildHtml('header') ?>
        <div class="main-container custom-layout-container">
            <div class="main">
                <?php echo $this->getChildHtml('breadcrumbs') ?>
                <div class="col-main">
                    <?php echo $this->getChildHtml('global_messages') ?>
                    <?php echo $this->getChildHtml('content') ?>
                </div>
            </div>
        </div>
        <?php echo $this->getChildHtml('footer') ?>
        <?php echo $this->getChildHtml('before_body_end') ?>
    </div>
</div>
<?php echo $this->getAbsoluteFooter() ?>
</body>
</html>

I hope it will be of help to you.

0
votes

Take a look at /app/code/core/Mage/Page/etc/config.xml you will see what you need to add to your own xml file.

<global>
    <page>
        <layouts>
            ...
        </layouts>
    </page>
</global>