Magento: The Best Way To Use Code In CMS Pages

We recently saw how to avoid issues with Magento editor to edit content on CMS pages (such as the home page for example) but I wanted to take the time to post a much better way to handle content in CMS pages with Magento.

You can use the editor if all you use is text and images with minor formatting. But if you have a more complex content with custom code, then it is much better to create a phtml file with your code in it (name it “page.phtml” for example) and put it here:

app/design/frontend/default/yourtheme/template/page/page.phtml

Then use this code in the CMS admin to call your content:

{{block type="core/template" template="page/page.phtml"}}

This method is the best way to use custom code in Magento CMS pages (such as the home page).

Don’t forget! Subscribe and follow!

Be sure to subscribe to the feed and follow us on Twitter for more tips, resources, and giveaways!

6 Comments

  • Wagnon
    Hey, I really appreciate your work in this post. Cheers
  • Juergen
    Thank you very much!
  • Jenna
    Thank you! This just saved me hours :)
  • Irv
    Hi thank you for this post… this may seem simple but what if the page I am trying to create on this CMS page uses js and jquery language and image folders. do I need to create more than one phtml page for this one CMS section? I tried what you mentioned and the page does not show correctly. I have left a link here maybe you can help…

    This is the page I made with your code:
    http://newschoolacademia.com/main/index.php/testslider

    I am trying to get this page working inside the CMS page:
    http://newschoolacademia.com/main/Demo/index.html

    Please any feedback will help.

  • Irv
    I figured it out! Thanks
  • mustkara
    My version is ver. 1.5.1.0

    I disable all the WYSIWYG Editor
    Enable WYSIWYG Editor->Disabled Completely
    Use Static URLs for Media Content in WYSIWYG for Catalog -> No

    However, the HTML code is still work correctly in Description attribute. However, it works in Short Description.
    I compare the attribute Short Description and Description and both have same setting. So, I believe the setting is correct but don’t know why unable to work with HTML code

    Please help

    Mustkara

Leave a Reply

Sorry - this blog is now closed to new comments.