0

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

2

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 */}
  • I tried your second and third suggestion, but they didn't actually add the class, and I don't know why. The first option did exactly what I wanted. – David Wilkins Jan 16 '15 at 19:12
  • On a side not of mine, this has helped me in my understanding of Magento greatly. Thanks – David Wilkins Jan 16 '15 at 19:14
  • @DavidWilkins Without more information I wouldn't be able to tell you why approach 2 and 3 didn't work for you, glad you were able to get it with approach #1 though. Please consider accepting this answer if it has worked out for you. – Darren Felton Jan 16 '15 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.