Magento – Equivalent of the CMS Directive {{media url=”…”}} in Normal Block Templates

blockscmsmediaurl

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)

Best Answer

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

Related Topic