0

What is the best way of getting the URL path of the current admin skin theme directory.

I am aware of

Mage::getModel('core/design_package')->getSkinUrl();

Which will return the URL of the front-end skin theme directory. Is there an Adminhtml equivalent?

Many thanks

Gerard de Visser
  • 7,590
  • 9
  • 50
  • 58
Chris Rogers
  • 1,525
  • 2
  • 20
  • 40

3 Answers3

3

For admin skin url, you can use:

<?php echo Mage::getDesign()->getSkinBaseUrl(array('_area'=>'adminhtml')) ?>

This method can be found in app/code/core/Mage/Core/Model/Design/Package.php.

You can also pass other params via the array like _package and _theme if you want the url of certain package/theme.

Gerard de Visser
  • 7,590
  • 9
  • 50
  • 58
2

This is the best way to get a secure skin URL:

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

To get an insecure skin URL:

$this->getSkinUrl('images/imagename.jpg');
ajshort
  • 3,684
  • 5
  • 29
  • 43
  • Sorry bro, I'm looking for the skin URL of the admin from the front-end. If I used $this from front-end surely I'll get a front-end URL? – Chris Rogers Mar 06 '16 at 12:59
2

Core Magento uses this in core code:

Mage::getDesign()->getSkinUrl('images/image.gif');

Which calls:

public static function getDesign()
{
    return self::getSingleton('core/design_package');
}

They are both equivalent except that $this may not work in all contexts/cases so I would recommend using Mage::getDesign() to avoid having issues.

PHP 5.3 has some issues using $this in some contexts.

You should be able to use Mage::getSingleton('core/design_package'); consistently as well.

Magento identifies which 'area' you're calling getDesign from so...

To evoke adminhtml or frontend areas and get their skin urls use:

$oDesign = Mage::getDesign()->setArea( 'adminhtml' );
$oDesign = Mage::getDesign()->setArea( 'frontend' );
var_dump( $oDesign );
$sUrl = $oDesign->getSkinUrl('images/image.gif');
var_dump( $sUrl );
Vladimir Ramik
  • 1,920
  • 2
  • 13
  • 23
  • Many thanks for your answer. What if you are in the front-end (when calling in a layout file for example) and wish to access the back-end URL? Using the above code would surely return the front-end path right? – Chris Rogers Mar 07 '16 at 07:43
  • I updated the answer on how to call admin from frontend and vice versa – Vladimir Ramik Mar 07 '16 at 23:56