I've had a few scenarios where I've tried to use the cms handles to update a cms page's layout. For example I was trying to use the cms_index_index handle referencing root and setting the page template. This failed and I had to make this layout update via the admin system directly on the homepage cms page display settings.
I've also tried to add a block to reference left using the cms_page handle. Again this failed and I had to implement the layout update via the admin system.
I've read that you can't assign a root template to cms pages. Is that correct and can anyone explain why?
I also wondered if there was a way to enable cms handles to use the standard references such as left, right, root etc? I seem to be able to reference things like head and content just fine.
Best Answer
Why changing the root template doesn't work
Both
and
which are responsible for displaying the default homepage and a CMS page respectively call a helper:
If you jump into the helper (located at app/code/core/Mage/Cms/Helper/Page.php) and follow
renderPage()
to the protected method_renderPage()
you'll see that Magento is checking two times for a root template (Magento CE 1.7.0.2):and
Both calls happen after layout handles like "cms_page" and the like are processed, so you are out of luck here.
What you can do to change the root template
There is an event
cms_page_render
which you can use for adding your own XML layout handle on CMS pages. Create your own extension (I'll spare some details here) and configure the event observer in yourconfig.xml
:Add your event observer:
Finally, add your new layout XML handle (e.g. in your
local.xml
):You can use this method as well to add a
cms_page_view_after
handle or create page specific handles ascms_page_render
passes the$page
object to your observer.Why you can't add a block to the 'reference left'
Are you sure that the template you're using has a left column? This question may sound silly but the default "2 columns with right bar" layout for example only offers a 'content' and a 'right' area. I can add blocks to the right column using
cms_page
without problems so this could be the problem.In general, you can only easily add blocks to references and echo them if
app/design/frontend/base/default/template/page/*.phtml
) andcore/text_list
, calls$this->getChildhtml()
without arguments or does something else to echo all child blocks.Without further details, I can't tell you why your blocks are not echo'd in the left or right column.