Magento – How to Change the Design for a Single CMS Page Content Heading

cmsdesign

I've been trying to set a custom design for a cms page, but I can't seem to figure out how to reference it. I just need to add a class to it, so I created a template as in the instructions here only I want to change the Content Heading, not the page header.

What block should I be referencing?

I tried this:

<reference name="content">
<block type="core/template" name="page_content_heading">
    <action method="setTemplate"><template>cms/headers/custom.phtml</template></action> 
</block> 
</reference> 

But that also displayed my custom design at the bottom of the page

Best Answer

You already got it, "page_content_heading". You just need to reference it rather than adding it over again

<reference name="page_content_heading">
    <action method="setTemplate"><template>cms/headers/custom.phtml</template></action>
</reference>

On a similar topic, if you're literally just looking to add a class to the file, may I recommend using the original template file (copied to your theme of course) and adding the class conditionally.

Somewhere in your template file:

<?php if ($this->getData('added_class')): ?><?php echo $this->getData('added_class') ?><?php endif ?>

Then, you can add whatever class you want with a XML layout update:

<reference name="page_content_heading">
    <action method="setData"><key>added_class</key><val>YOUR_CLASS_NAME</val></action>
</reference>

That way you don't need to have a whole bunch of different .phtml files for the same purpose should you need to start adding different classes per CMS page.

On ANOTHER note... you could just add a class to the body tag without the need to customize any view script.

<reference name="root">
    <action method="addBodyClass"><class>YOU_CLASS_NAME</class></action>
</reference>

Then in your CSS file target the page header using the body class as well:

.YOUR_BODY_CLASS .page-title h1{/* style rules */}