Get base URL, Media URL, JS URL, Skin URL, Store URL, and Current URL

Basic Questions in magento’s developer mind when start theme development.

  • How to get Base URL in .phtml file.
  • How to get Skin URL in .phtml file.
  • How to display image in CMS page or Static Block.
  • How to get Media URL.
  • How to get JS URL.
  • How to get Store URL.
  • How to get Current URL.

Below are answer available for all above Questions.

Get URL in phtml files.

  1. Get Base Url :

    Mage::getBaseUrl();

  2. Get Skin Url :

    Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

    • Unsecure Skin Url :

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

    • Secure Skin Url :

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

  3. Get Media Url :

    Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

  4. Get Js Url :

    Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

  5. Get Store Url :

    Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

  6. Get Current Url :

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

Get URL in static block or CMS page.

  1. Get Base Url :

    {{store url=""}}

  2. Get Skin Url :

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

  3. Get Media Url :

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

  4. Get Store Url :

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