How To Fake a Magento Subpage


/ Published in: PHP
Save to your folder(s)

agento, an open-source PHP ecommerce solution, has a very comprehensive feature list. However, its built-in CMS doesn’t support hierarchical pages. You can fake it, though.

Let’s say you have a page with an SEF (search engine friendly) URL Identifier of “foo”. You’d like to have a subpage “bar” nested under foo. The CMS doesn’t let you create parent-child relationships, but Magento will let you include forward slashes in the SEF URL Identifier so that it is “foo/bar”.

That’s the good news. The bad news is if you want to use the breadcrumbs block, it won’t work out of the box. The Magento CMS is flat, so the default breadcrumbs will always look like “Home / My Page Title.” The optimal solution is to override the breadcrumbs module and parse the SEF URL Identifier and construct the breadcrumbs from that. (I may write a post about it in the future so stay tuned.) The good news for those designers out there, you don’t have to dive into code.

Magento’s CMS has a feature where each page has a way to override its XML layout. When you’re editing a page, go to the “Custom Design” tab. There you’ll see a form field called “Layout Update XML”. This is the key. Here’s where you add XML to first unset the breadcrumbs block and then add it back in but with your specific breadcrumbs. Here’s the code:


Copy this code and paste it in your HTML
  1. <reference name="root">
  2. <action method="unsetChild"><alias>breadcrumbs</alias></action>
  3. </reference>
  4.  
  5. <reference name="root">
  6. <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
  7. <action method="addCrumb">
  8. <crumbName>home</crumbName>
  9. <crumbInfo><label>Home</label><title>Go to Home Page</title><link>/</link></crumbInfo>
  10. </action>
  11. <action method="addCrumb">
  12. <crumbName>foo</crumbName>
  13. <crumbInfo><label>Foo</label><title>Foo</title><link>/foo/</link></crumbInfo>
  14. </action>
  15. <action method="addCrumb">
  16. <crumbName>cms_page</crumbName>
  17. <crumbInfo><label>Bar</label><title>Bar</title></crumbInfo>
  18. </action>
  19. </block>
  20. </reference>

URL: http://www.lindenlan.net/2009/04/21/how-to-fake-a-magento-subpage/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.