2

I need to set images from the Magento media folder but index.php keeps getting in the way and since I'm going to be moving this dev site to another production URL, I can't just use hard paths in this case.

In Wordpress/Drupal I can set a link like <img src="<?php echo home_url(); ?>/media/image-name.jpg" /> but I can't find anything similar to that for Magento.

I'm needing this for the static blocks section if that makes a difference. When I try to set relative links to http://mysite.com/media/image-name.jpg I end up with http://mysite.com/index.php/media/image-name.jpg which of course results in 404.

What do I need to put in static blocks that will reference the main site without the index.php?

1

2 Answers 2

2

Well, the canonical way to get the media url is:

Mage::getBaseUrl('media');

so you in phtml you can do

<img src="<?php echo Mage::getBaseUrl('media'); ?>image-name.jpg" />

but in static blocks you need template syntax:

{{media url='image-name.jpg'}}
1
  • Excellent. This was very helpful.
    – o_O
    Jun 18, 2014 at 7:14
0

You can use

<img src="<?php echo Mage::getBaseUrl(); ?>media/image-name.jpg" />

Take a look on this article. It lists all type of url methods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.