Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get skin path in Magento?

I have a few custom PHP functions for my Magento store that I stored in myfunc.php and I need to require it from in a few different .phtml files. How do I do that?

I mean I can use an absolute path but that would be dirty and probably problematic when migrating to another server.

For now I'm stuck with:

require('/home/myuser/public_html/app/design/frontend/default/mytheme/myfunc.php'); 

How do I refer to the skin path ( /home/myuser/public_html/app/design/frontend/default/mytheme/ ) programmatically?

like image 570
datasn.io Avatar asked Apr 28 '12 02:04

datasn.io


2 Answers

The way that Magento themes handle actual url's is as such (in view partials - phtml files):

echo $this->getSkinUrl('images/logo.png');

If you need the actual base path on disk to the image directory use:

echo Mage::getBaseDir('skin');

Some more base directory types are available in this great blog post:

http://alanstorm.com/magento_base_directories

like image 149
philwinkle Avatar answered Oct 02 '22 18:10

philwinkle


First note that

Mage::getBaseDir('skin') 

returns only path to skin directory of your Magento install (/your/magento/dir/skin).

You can access absolute path to currently used skin directory using:

Mage::getDesign()->getSkinBaseDir() 

This method accepts an associative array as optional parameter to modify result.

Following keys are recognized:

  • _area frontend (default) or adminhtml
  • _package your package
  • _theme your theme
  • _relative when this is set (as an key) path relative to Mage::getBaseDir('skin') is returned.

So in your case correct answer would be:

require(Mage::getDesign()->getSkinBaseDir().DS.'myfunc.php'); 
like image 21
Deus777 Avatar answered Oct 02 '22 17:10

Deus777