What is the equivalent of {{media url="wysiwyg/image.jpg"}}
which can be used in CMS pages if we want to use this in a normal .phtml
file (of the type core/template
)
2 Answers
The rendering of this such URLs is done when displaying CMS pages or blocks in
\Mage_Core_Model_Email_Template_Filter::mediaDirective
:
public function mediaDirective($construction)
{
$params = $this->_getIncludeParameters($construction[2]);
return Mage::getBaseUrl('media') . $params['url'];
}
Base on this code, just an
<img src="<?php echo Mage::getBaseUrl('media') ?>image.jpg">
can be used in the template
-
2Just remove the blockquote(
`
) from the second code snippet (after?>image.jpg">
). (I can't edit less than 6 letters)– HimanshuCommented Sep 21, 2013 at 8:13 -
2+1 But it may be better to pass
Mage_Core_Model_Store::URL_TYPE_MEDIA
instead of'media'
? Commented Nov 11, 2014 at 21:04
In a phtml template file:
Mage::getBaseUrl('media') . $url;
In a CMS block or page:
{{store direct_url="media/url"}}
The difference between {{media url="foo"}}
and {{store direct_url="media/foo"}}
is that the latter hardcodes the media directory path as media
.
That might lead to issues when using a CDN or something, because it bypasses Mage::getBaseUrl('media')
.
-
what is the difference between
{{store direct_url="media/url"}}
and{{media url="foo"}}
?– AlexCommented Jun 14, 2013 at 15:04 -
-
Thank you. I also edited my question to make it more clear - I want the full URL of a picture. Actually I would be happy to accept my own answer ;-) --- as I know my problem best :-P– AlexCommented Jun 16, 2013 at 12:07
-
4Note that: {{store direct_url="media/url"}} -> If mod_rewrite is disabled, this may introduce the index.php in the url, hence breaking the media url. Commented Jun 16, 2013 at 12:15
-
1@MagePsycho: good point. Lucky I've never had ha store with mod_rewrite disabled.– VinaiCommented Jun 16, 2013 at 16:12