I'm building a custom module, a very simple blog. I already have everything working. The last thing I added, was de WYSIWYG image upload capability.

In the Admin, everything works fine. But in the fronted, I see the raw source code and the <img> tags are filled with: {{media url="wysiwyg/some_image.jpg"}}

If I navigate to /pub/media/wysiwyg/some_image.jpg, the jpg exists. But I can't figure out how to change this via some helper or function to get it right in the front end.


You can filter its using filter() function,

$content = 'This is test demo imgage, {{media url="wysiwyg/some_image.jpg"}}';
$om = \Magento\Framework\App\ObjectManager::getInstance();
$filterManager = $om->get('Magento\Cms\Model\Template\FilterProvider')->getPageFilter()->filter($content);
echo $filterManager;
| improve this answer | |

You need declare this Class in constructor of Block:

Magento\Cms\Model\Template\FilterProvider $filterProvider

$content = '{{media url="wysiwyg/some_image.jpg"}}';
$contentGenerating = $this->_filterProvider->getPageFilter()->filter($content);
echo $contentGenerating; //Generate HTML <img src="http://baseUrl/pub/media/wysiwyg/some_image.jpg"/>

I hope it help you.

| improve this answer | |

You need to add processor for WYSIWYG content to display on frontend. It will process all the variables used in the editor and display it with its values. If you have the content in a variable.

$content = $myContent;
echo Mage::helper('cms')->getPageTemplateProcessor()->filter($content);
| improve this answer | |
  • 1
    this is not for magento 2 – Blueblazer172 Nov 8 '17 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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