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

Get Url in phtml files

1. Get Base Url :

Mage::getBaseUrl();

2. Get Skin Url :

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

(a) Unsecure Skin Url :

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

(b) 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 cms pages or static blocks

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'}}
Tags:  ,

Comments

shajar 25-06-2012, 15:49

Good help for begginners

Reply
Pawel 18-01-2013, 18:56

Hi. Do You know how o get secure url in CMS Pages/Static Blocks?

Reply
Jagdeep Banga 06-05-2013, 10:36

Hi Pawl,

Try {{secure_base_url}} in CMS Pages/Static blocks.

Reply
Trabant 20-01-2013, 05:08

Thank! Helped me a LOT as new user. Why? I installed Magento on a VPS (managed) WITHOUT a domainname. Just the IP/path to get there. Succesfully installed Magento. The domainname is going to be redirected later through DNS.
But afer adding (succesfully) a second store with another parked domain I could not get it work with its own theme :-( Searched for hours….
As many tuto’s say that you only have to change the Base URL under Config -> General -> Web this did not work for me.
After I read about the code above I finaly found out tha the base url was different from the Base Skin/Media?JavaScipt URL.
So in this case I had to set the Base URL to the actual domain eg. “http://mysite2.com/” and for others I hade to use the path to my server eg. ”http://thepath.to.myserver.at.server1234/”
Just had to leave Base Link URL to {{unsecure_base_url}}

Now it all works just fine! Two stores, two domains, two catalogues and finaly also two themes :-)

THANK YOU! <3

Reply
Tapan Kumer Das 17-03-2013, 03:18

Thanks a lot. You save my lot of time. This cheat sheet is bookmarked for later use.

Reply
clear 02-04-2013, 09:40

I am genuinely delighted to read this web site posts which
contains tons of helpful facts, thanks for providing these kinds of
information.

Reply
Danson 23-07-2013, 01:43

Very good post, clear and easy to follow

Reply
MagePsycho 13-08-2013, 14:04

$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();
}
Source: http://www.blog.magepsycho.com/how-to-find-current-url-in-magento/

Reply
Matt 28-05-2014, 20:42

Great reference for the days my brain isnt switched on to quickly grab magento url ref’s.

Reply

Leave a Reply



− four = one


Warning: Invalid argument supplied for foreach() in /home/jagdeepb/public_html/wp-content/plugins/gantry/core/gantrygzipper.class.php on line 145

Warning: Invalid argument supplied for foreach() in /home/jagdeepb/public_html/wp-content/plugins/gantry/core/gantrygzipper.class.php on line 151