Quantcast
Channel: Ghan – Code Insects – Insects who Code
Viewing all articles
Browse latest Browse all 26

How to get base URL, Skin Url, JS URL, Media URL, Current URL in magento?

$
0
0

While working on magento themeing, we need to get some url(s) in temlate (phtml) file or cms pages/block in magento adminstration panel.

here I am gonna show you how to get these url(s) in template file or cms pages/block

getting url(s) in phtml

  • Get Base Url of magento e.g. (http://www.example.com)

    1
    
    Mage::getBaseUrl();
  • Get active Skin url in magento (http://www.example.com/skin/frontend/<activepackage>/<activetheme>)

    1
    
    Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
  • get url for image,css etc in skin directory (http://www.example.com/skin/frontend/<activepackage>/<activetheme>/<js|css|images>/<filename>)

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

    if you are looking for to get the above url in secure mode like (https://www.example.com/skin/frontend/<activepackage>/<activetheme>/<js|css|images>/<filename>)

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

    or if you forecfully want to get secure url then:

    1
    
    $this->getSkinUrl('images/imagename.png', array('_forced_secure'=>true));
  • Get Media Url (http://www.example.com/media)

    1
    2
    3
    4
    5
    6
    7
    
    Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
    <pre>
    </li>
    <li>
    <p>get Js Url(http://www.example.com/js/)</p>
    <pre lang="php" line="1">
    Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

    Note: if you want to get js url from skin directory than using following code

    1
    
    $this->getSkinUrl('js/customjs.js');
  • Get Current Url

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

getting url(s) in cms block or cms pages in administration panel

  • Get Base Url of magento e.g. (http://www.example.com)

    1
    
    {{store url=""}}
  • get url for image,css etc in skin directory (http://www.example.com/skin/frontend/<activepackage>/<activetheme>/<js|css|images>/<filename>)

    1
    
    {{skin url='images/imagename.png'}}
  • Get Media Url (http://www.example.com/media/abc.jpg)

    1
    
    {{media url='/abc.jpg'}}

Viewing all articles
Browse latest Browse all 26

Trending Articles