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?
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
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:
So in your case correct answer would be:
require(Mage::getDesign()->getSkinBaseDir().DS.'myfunc.php');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With