Handy Reference for Magento URL Path Snippets

Always scratching your head while trying to remember the correct code snippet to get the base url, store url, or media url path when working in Magento? Yeah… me too. Here’s a handy list of the most commonly needed snippets for my reference–and yours!

Magento URL path for use in CMS Blocks & Pages

To get the skin URL:

{{skin url='images/example.jpg'}}

To get the media URL:

{{media url='example.jpg'}}

To get the store URL:

{{store url='example.html'}}

To get the base URL:

{{base url=''}}

Magento URL path for use in .phtml files

Get the unsecure skin URL:

<?php echo $this->getSkinUrl('images/example.jpg') ?>

Get the secure skin URL:

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

Get the current URL:

<?php $current_url = Mage::helper('core/url')->getCurrentUrl();?>

Get the home URL:

<?php $home_url = Mage::helper('core/url')->getHomeUrl();?>

Get the Magento media URL:

<?php Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);?>

Get the Magento skin URL:

<?php Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);?>

Get the Magento store URL:

<?php Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>

Get the Magento JS URL:

<?php Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);?>

H/T to PlazaThemes.com for their list. I have used it several times and for fear of it ever disappearing I have re-posted it here. Also, their snippets have curly quotes in them which annoyed the hell out of me.

If you notice that any of these snippets are out-of-date, please comment and share your knowledge!

Published by

Brian Lyman

Brian is the founder of Vale Studios, which is really just a stage name for what has been a great experience in freelancing. Brian is currently working under a dedicated contract for a terrific e-commerce retailer, but he uses this space to continue publishing ideas and reflections related to e-commerce, marketing, and Magento.

Leave a Reply

Your email address will not be published. Required fields are marked *