Magento : Get Base Url , Skin Url , Media Url , Js Url , Store Url and Current Url.

Get Url in phtml files

TO Retrieve URL path in PHTML

Note: In editing PHTML don’t forget to change the following code with PHP tag

(a) Unsecure Skin Url :

$this->getSkinUrl('images/imagename.jpg');

(b) Secure Skin Url :

$this->getSkinUrl('images/imagename.gif', array('_secure'=>true));

1. Get Magento Base Url :

Mage::getBaseUrl();

2. Get Magento Skin Url :

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

3. Get Magento Media Url:

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

4. Get Magento Js Url:

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

5. Get Magento Store Url:

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

6. Get Magento Current Url:

Mage::helper('core/url')->getCurrentUrl();

Get Url in cms pages or static blocks

1. Get  magento Base Url :

{{store url=""}}

2. Get magento Skin Url :


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

3. Get magento Media Url :

{{media url='/imagename.jpg'}}

4. Get magento Store Url :

{{store url='mypage.html'}}
Advertisements

3 thoughts on “Magento : Get Base Url , Skin Url , Media Url , Js Url , Store Url and Current Url.

  1. $currentUrl = Mage::helper(‘core/url’)->getCurrentUrl()
    or
    $currentUrl = Mage::getUrl(‘*/*/*’, array(‘_current’ => true));
    above code may not work always as expected.
    Better way to find the current url is to use the following code:

    if (!in_array(Mage::app()->getFrontController()->getAction()->getFullActionName(), array(‘cms_index_noRoute’, ‘cms_index_defaultNoRoute’))) {
    $currentUrl = Mage::helper(‘core/url’)->getCurrentUrl();
    }

Leave your comments

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s