Magento – Inserting a block in a CMS page between content heading and content

blockscmsxml

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)

Best Answer

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').

Related Topic