Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Get current skin directory
 
Tensor
Jr. Member
 
Total Posts:  7
Joined:  2008-06-14
 

I have a php script that displays a random image and I’d like to store those images in the images directory for the currently selected skin. I assume there’s a way to get the directory for the current skin, so instead of using skin/frontend/default/default/images/image.jpg, I’d like to use Magento’s code to get the correct path to the images folder (in case the skin changes in the future). Anyone know how to do this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
mike222
Member
 
Total Posts:  41
Joined:  2008-04-07
Austria
 

For someone willing to answer the above question: I would like to use the same feature from within a CMS page or static text.

Therefore instead of writing
<img src="/shop/skin/frontend/default/myTheme/images/logo.gif"/>
I would rather like to write
<img src="<$variable/images/logo.gif"/>

into the cms content.

Thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
 
lazzymonk
Guru
 
Avatar
Total Posts:  391
Joined:  2008-04-03
England
 

for within php files use this

<?php echo $this->getSkinUrl('images/image.jpg'); ?>

and for within cms pages use

{{skin url="images/logo.gif" }}

 
Magento Community Magento Community
Magento Community
Magento Community
 
sdb
Sr. Member
 
Avatar
Total Posts:  223
Joined:  2007-11-13
coastal California, USA
 

sweet, ive been wondering about this one for a while. i hate using absolute image paths these days if i can avoid it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tensor
Jr. Member
 
Total Posts:  7
Joined:  2008-06-14
 

That helps, but it gives me the URL, not the directory. The problem is I’m using a script to get a random image from a directory, and a URL doesn’t work for that (AFAIK). I did find a way around it, but I’m not sure how good a solution it is:

$dir parse_url($skinURL,PHP_URL_PATH);
$dir $_SERVER['DOCUMENT_ROOT'].$dir;
That gives me the directory, and then I get a random file, and tack that filename onto the end of the skin URL.
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top