CMS page, .phtml page and php page in Magento

This post is use for get skin url, get media url, get base url, get store url and other url of magento. In this post we can get url of static block , CMS page, .phtml page and php page in Magento.

Get skin url in static block

Example :

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

Get Media url in static block
Example :

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

Get Store url in static block
Example :

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

Get Base url in static block
Example :

{{base url = ''}}

Get URLs in templates/PHTML/PHP files

Get Base Url in magento templates/PHTML/PHP:

    // Get Base Url
    $base_url = Mage::getBaseUrl();
    echo $base_url;

Get Base Url without index.php in templates/PHTML/PHP:

    // Get Base Url ithout index.php
    echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); 
    // output: http://onlinecode/

Get Current Url in templates/PHTML/PHP:

    // get Current Url
    $current_Url = Mage::helper('core/url')->getCurrentUrl();

    // or
    // get Current Url
    $current_Url = Mage::getUrl('*/*/*', array('_current' => true));

    // or
    // get Current Url
    if (!in_array(Mage::app()->getFrontController()->getAction()->getFullActionName(), array('cms_index_noRoute', 'cms_index_defaultNoRoute')))  // Current Url 
    {
        $current_Url = Mage::helper('core/url')->getCurrentUrl(); // get Current Url
    }
    echo $current_Url;

Get Skin URL in templates/PHTML/PHP:

    // Get Skin URL
    $skin_Url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

    Get Unsecure Skin URL in templates/PHTML/PHP
    // Get Unsecure Skin URL
    $skin_Url = $this->getSkinUrl('images/imagename.jpg');

Get Secure Skin URL templates/PHTML/PHP:

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

Get Media URL templates/PHTML/PHP:

    $media_Url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

    // or

    $media_Url = Mage::getBaseUrl('media');

Get Js URL templates/PHTML/PHP:

    $js_Url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

    // or

    $js_Url = Mage::getBaseUrl('js');

Get store URL templates/PHTML/PHP:

    $store_Url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

    Get Home URL templates/PHTML/PHP

    $home_Url= Mage::helper('core/url')->getHomeUrl();

Get Directory paths templates/PHTML/PHP:

    echo Mage::getBaseDir('design') // Get file path of design directory
    echo Mage::getBaseDir('code')   // Get file path of code directory 
    echo Mage::getBaseDir('lib')    // Get file path of lib directory
    echo Mage::getBaseDir('skin')   // Get file path of skin directory
    echo Mage::getBaseDir('var')    // Get file path of var directory
    echo Mage::getBaseDir('cache')  // Get file path of cache directory
    echo Mage::getBaseDir('log')    // Get file path of log directory

Get Create module URL templates/PHTML/PHP:

    echo Mage::getUrl('module/controller/action');

Leave a Comment

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

1  +  5  =  

We accept paid advance and paid guest Posting on our Site : Contact US