Magento Themes and Magento Extensions

Magento Tips and Snippets

Share

Magento has become quite a popular system in recent months.. snippets, tutorials, and other resources are in high demand for the system. Let’s look at some pros and cons of Magento and then some useful code snippets..

The Good

All around, Magento beats the competition. Here are just a few highlights if you’re not familiar with Magento:

  • Magento is Object Oriented
  • Magento is secure and scalable
  • Magento has a large community that is rapidly growing
  • Magento can be extended very easily
  • Magento allows for multiple stores and store fronts

The Bad

Magento has a few things that I’m not too excited about:

  • Magento is HUGE and bulky
  • Magento lacks a WYSIWIG and CMS
  • Magento uses a lot of JavaScript in a bad way

Some Useful Code

I’ll feed you baby birds..

Add a CMS Static Block to a page:
Within Magento:

{{block type="cms/block" block_id="identifier"}}

With PHP:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('identifier')->toHtml() ?>

Display products from a specific category on the page:
Many people ask how to display products on the home page.. this is the easiest and most universal solution. Replace category ID with whatever category you want to display

{{block type="catalog/product_list" template="catalog/product/list.phtml" catagory_id="0"}}

Shortcuts:
Store URL within Magento:

{{store url=""}}

Define a new CMS Page Layout

Depending on what version of Magento you’re running, this may be different, but in the 1.3x series, this is how you’d define a new page layout. We’ll define a layout called home for this example:

/app/code/core/Mage/Page/etc/config.xml

        <page>
            <layouts>
                <empty module="page" translate="label">
                    <label>Empty</label>
                    <template>page/one-column.phtml</template>
                    <layout_handle>page_empty</layout_handle>
                </empty>
                <one_column module="page" translate="label">
                    <label>1 column</label>
                    <template>page/1column.phtml</template>
                    <layout_handle>page_one_column</layout_handle>
                </one_column>
                <two_columns_left module="page" translate="label">
                    <label>2 columns with left bar</label>
                    <template>page/2columns-left.phtml</template>
                    <layout_handle>page_two_columns_left</layout_handle>
                </two_columns_left>
                <two_columns_right module="page" translate="label">
                    <label>2 columns with right bar</label>
                    <template>page/2columns-right.phtml</template>
                    <layout_handle>page_two_columns_right</layout_handle>
                </two_columns_right>
                <three_columns module="page" translate="label">
                    <label>3 columns</label>
                    <template>page/3columns.phtml</template>
                    <layout_handle>page_three_columns</layout_handle>
                </three_columns>
                <home>
                	<label>Home</label>
                	<template>page/home.phtml</template>
                	<layout_handle>page_home</layout_handle>
                </home>
            </layouts>
        </page>

Please understand that this is editing the core and will not be protected in an upgrade/update. To properly define this to be compatible with future upgrades, you’ll need to define a simple module to override the core with a local file.

Comments are closed.