Looking to Increase Revenue From Your Website?

Schedule a FREE 30-minute power consultation now.

Magento Snippet Cheat Sheet

I work on a lot of Magento sites and figured it would be great to have all the various Magento code snippets  in one place for easy reference. Hopefully you will find this as useful as I do.

Static Block in PHTML File

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


Static block in CMS Page

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


Attribute Text in PHTML File

<?php echo $_product->getIdentifier_goes_here() ?>


Secure URL for Image in PHTML File

<?php echo $this->getSkinUrl('images/image_name.png', array('_secure'=>true)) ?>


Non-Secure URL for Image in PHTML File

<?php echo $this->getSkinUrl('images/image_name.png') ?>


Image URL in CMS Page

{{skin url="images/image_name.png"}}


Store URL in CMS page

<a href="{{store url=""}}url_key"></a>


CMS Page URL in PHTML File

<?php echo $this->getUrl('cms_url_key'); ?>


Add Custom CSS or JS Calls to Pages/Categories

<reference name="head">
<action method="addJs"><script>prototype/lightbox.js</script></action>
</reference>

<reference name="head">
<action method="addCss"><script>css/lightbox.css</script></action>
</reference>


Add Store ID to PHTML Template File

<?php $store_id = $this->helper('core')->getStoreId(); echo $store_id; ?>


More to come…did I miss anything?

Looking to Increase Revenue From Your Website?

Schedule a FREE 30-minute power consultation now.