0

I am trying to add a custom block on all CMS pages after the page's Content Heading but before the page's Content.

For reference, this is what is in my theme's layout/cms.xml, I haven't touched it:

<cms_page translate="label">
    <label>CMS Pages (All)</label>
    <reference name="content">
        <block type="core/template" name="page_content_heading" template="cms/content_heading.phtml"/>
        <block type="page/html_wrapper" name="cms.wrapper" translate="label">
            <label>CMS Content Wrapper</label>
            <action method="setElementClass"><value>std</value></action>
            <block type="cms/page" name="cms_page"/>
        </block>
    </reference>
</cms_page>

The content of cms/content_heading.phtml is just this (the heading, as expected), again, haven't touched it:

<?php if($_heading = $this->getContentHeading()): ?>
    <div class="page-title">
        <h1><?php echo $_heading; ?></h1>
    </div>
<?php endif; ?>

In my local.xml file, I am adding this:

<default>
    <reference name="content">
        <block type="core/template" name="my.new.block" after="page_content_heading" template="callouts/my_new_block.phtml" />
    </reference>
</default>

This is putting the block below the Content Heading AND the Content of the page.

I have also tried this (adding "before" tag):

<default>
    <reference name="content">
        <block type="core/template" name="my.new.block" before="cms_wrapper" after="page_content_heading" template="callouts/my_new_block.phtml" />
    </reference>
</default>

This is the same as above.

What am I missing? Thanks very much for any help.

(FYI, I am flushing my cache regularly. I'm using Magento 1.8.1)

  • try to disable Magento cache entirely and remove cache folder magento-root/var/cache – Aboodred1 May 1 '14 at 15:59
  • I have tried both of those suggestions too, the cache is not the problem because the changes I am making are having an effect, just not the effect I'd like! – Sarah May 2 '14 at 9:15
1

Have you tried adding a root block between label and content? As follows:

<reference name="root">
    <block type="core/template" name="my_header" as="my_header" template="cms/default/my_header.phtml" />
</reference>

So, for clarity:

<cms_page translate="label">
    <label>CMS Pages (All)</label>
    <!-- ROOT BLOCK HERE -->
    <reference name="content">
        ....
    </reference>
</cms_page>

This block can be called in the view using getChildHtml('my_header').

  • Thanks for your suggestion, can I ask which template file you would suggest I put getChildHtml('my_header') in? – Sarah May 2 '14 at 9:10
  • @Sarah That depends on your theme, you could go for app/design/frontend/base/default/template/cms/content_heading.phtml? – Jongosi May 2 '14 at 22:19
0

You're probably past this issue by now or at least, I'd hope so, but for anyone else who happens upon this post when looking for an answer to the same question, here is one option.

Instead of referencing content, reference cms.wrapper instead. Then use the before attribute with cms_page as the value. Your block will be inside of the div tag with the std class, but will be above all the other content within that tag.

<default>
    <reference name="cms.wrapper">
        <block type="core/template" name="my.new.block" before="cms_page" template="callouts/my_new_block.phtml" />
    </reference>
</default>

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.