Using Magento as a CMS

Making a page in Magento packed full of your lovely SEO keyword driven content is easy, really easy. But what happens when you want to get that content somewhere that isn't one of those pages? That's when everything falls apart...
Let's get this straight from the get go- Magento is not a content management system and at this point it's not really trying to be one... well, maybe just a little. It's got pages, templates and static blocks which can be embedded within each other. Confused? I'd suggest taking a look at the Design Terminologies page. With these 3 main tools and some imagination you can do quite a bit in terms of ensuring that content on a site is editable via the cms.
Unfortunately other than a brief front-end overview, Magento's developer documentation is non-existent. Luckily there's a pretty good community of developers willing to share what they've learned. Throughout my adventures with Magento I've kept a running list of different ways you can grab content from somewhere else, here's some of the most commonly used ones.
Embed a Static Block Within a Page
So you've got a static block of content that you want to put inside of a page, cool. Just drop this snippet in the page's content textarea and the static block with and id of "foo-block" will magically appear.
{{block type="cms/block" block_id="foo-block"}}Get a Static Block's Content From Within a Template File
This does the same thing as above except instead of being used in a page, it's used in a template file.
$this->getLayout()->createBlock('cms/block')->setBlockId('foo-block')->toHtml();Inserting a Template file Inside of a Page's Content
You'll notice the curly braces, that means it's a CMS tag like our first example. Just two things have changed, The type of block is different and in the template attribute you specify the path relative to your templates folder.
{{block type="core/template" template="path-to-template.phtml"}} Templates in Templates
You're in a template file and you want to include another template file in it, chances are you should probably be using Magento's block layout system for this rather than manually including it the template. Regardless of best practices, here's how it's done.
$this->getLayout()->createBlock('Mage_Adminhtml_Block_Template', 'block-name')->setData('template', 'path-to-your-file.phtml')->toHtml();Here is a great resource that dives deeper into various CMS syntax tags Magento CMS syntax – part1








Comments
Rob Zienert (not verified) says:
Published on Nov 17, 2009 @ 11:07am
You should write a blog post on extending Magento. Or maybe that would be for me.
My objective, unbiased and completely professional review of the Magento E-Commerce platform: It is one of the most tremendously heinous applications I've ever had to deal with. The greatest over-engineering abomination sent from the very most vile, wretched depths of the earth with it's sole objective to make a developer's life hell--laughing maniacally as you tip-toe through it's broken architecture, hoping not to fall into the dark chasms waiting to swallow your soul wholly for all eternity. Those who enter Magento lose a part of their humanity without hope of ever seeing it again. It lies waiting to victimize all who decide to leverage the power that which lies beneath.
Too much? Yeah, it's a pretty good system until you have to do crazy things with it.
Toni Anicic (not verified) says:
Published on Dec 8, 2009 @ 03:30am
Thanks for linking to us Zack. You're right, Magento is not much of a CMS. This is why we usually integrate it with WordPress for clients that need content management :)
Magento Technologies (not verified) says:
Published on Feb 10, 2010 @ 15:21pm
it is possible but why use Magento as CMS when you have so many great CMS platforms out there like wordpress?
It's really a must for developers to know how they will be using magento and clarify that they really need a magento site not a CMS
gabesz (not verified) says:
Published on Apr 21, 2010 @ 10:19am
If you want to embed a static block on the homepage only (landing page of the store), add the reference to the hompage under Admin > CMS > Manage Pages > Home page.
Post new comment