magentoskin

Magento - Get the Skin URL


I'd like to call the URL for my Magento store's skin for the purpose of loading an image. I've read that you can use <?php echo $this->getSkinUrl('images/ sampleimage.gif', array('_secure'=>true)) ?>, but I get a "Call to undefined method" by using that. I've tried looking for a Mage::getModel version of this method, but I can't find it.

I did find Alan Storm's article, which got me most of the way there: http://alanstorm.com/magento_base_directories. Alan says I can use Mage::getBaseDir(‘skin’), and I've found Mage::getSingleton('core/design_package')->getPackageName(). I can't find a way to get the last part of the skin directory. If my current skin was /skin/frontend/base/default/ I've so far got it to /skin/frontend/base/, I just need to be able to get Magento to give me the last, /default/, part of the directory.

I'm hoping that I'm barking up the wrong tree here and that there's a nice Mage::getModel method that I can call, like the $this->getSkinUrl. Can you help?


Solution

  • You are perfectly right in your assomption and the model is Mage_Core_Model_Design_Package

    So this do the trick :

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

    I did found that this way : I know the function I (or in this case you) are looking for, so I just try to get the file where it is :

    grep -Rni 'function getSkinUrl' .
    ./app/code/core/Mage/Core/Model/Design/Package.php:482:    public function getSkinUrl($file = null, array $params = array())
    

    Great, now I just have to translate the file to its handle so Mage/Core/Model/Design/Package becomes core/design_package

    As discovered during some core lookup in the comments, another way to do it would be simply to use:

    Mage::getDesign()->getSkinUrl()