Magento – Use custom layout handle for cms page view

layoutlayout-updateupdate-handle

I'm trying since hours to get my custom layout handle to work.
I have a cms page that calls the layout handle "cms_page_view".
Now I want to set in my custom module a new layout handle:

config.xml

<page>
    <layouts>
        <cms_page_view module="page">
            <label>My Page</label>
            <template>page/mypage.phtml</template>
            <layout_handle>cms_page_mypage</layout_handle>
        </cms_page_view>
    </layouts>
</page>

<frontend>
    <layout>
        <updates>
            <custom_mymodule>
                <file>custom/mypage.xml</file>
            </custom_mymodule>
        </updates>
    </layout>
</frontend>

In my new layout file (custom/mypage.xml):

<?xml version="1.0"?>
<layout>
    <cms_page_mypage translate="label">
        <label>MyPage</label>
        <reference name="root">
            <action method="setTemplate">
                <template>page/mypage.phtml</template>
            </action>
            <action method="setIsHandle">
                <applied>1</applied>
            </action>
        </reference>
        <block type="page/html_head" name="head_mypage" as="head_mypage">
            <action method="addItem"><type>skin_css</type><name>css/styles-ie.css</name><params/><if>lt IE 8</if></action>
            <action method="addItem"><type>skin_css</type><name>css/styles-ie8.css</name><params/><if>lt IE 9</if></action>
            <action method="addCss"><stylesheet>css/widgets.css</stylesheet></action>
            <action method="addCss"><stylesheet>css/print.css</stylesheet><params>media="print"</params></action>
        </block>
    </cms_page_mypage>
</layout>

In my cms page in the backend I wrote this in the conent area:

{{block type="core/template" name="my_page" as="content" template="page/html/my_page.phtml"}}

And in the end … nothing happens when I call my page/mypage.phtml with this content:

<head>
    <?php echo $this->getChildHtml('head_mypage') ?>
</head>

What am I missing here???

Best Answer

Try putting your "head_mypage" block declaration inside of <reference name="root">