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!