I want to get all content of WYSIWYG content display on my popup. When the WYSIWYG content has an image and text added then the image doesn't display.

I want to get output like that. If I added Bold effect on text and an image is added in the WYSIWYG content, then it will display output like bold font and the image is displayed. If I added just an image, then the image will be displayed in the popup. If I added just Bold effect on textm then it will displayed as bold text.

How can do like this?

  • I also found solution : $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $filterManager = $objectManager->get('Magento\Cms\Model\Template\FilterProvider')->getPageFilter()->filter($content); echo $filterManager; – Rohan Hapani May 8 '17 at 7:08
  • 1
    yes it's right but don't use object manager directly as Magento 2 standards. – Prince Patel May 8 '17 at 8:02
  • Okey... @PrincePatel – Rohan Hapani May 8 '17 at 10:25

Let's say your popup has a block behind it to handle the logic, and a template to render the result (as it should have).
Let's say your block class is \Vendor\Module\Block\Popup

Add this to your block.

 * @var \Zend_Filter_Interface
protected $templateProcessor;
public function __construct(
    \Zend_Filter_Interface $templateProcessor, 
) {
    $this->templateProcessor = $templateProcessor;

Then create the method:

public function filterOutputHtml($string)
    return $this->templateProcessor->filter($string);

In your di.xml file add this:

<type name="Vendor\Module\Block\Popup">
        <argument name="templateProcessor" xsi:type="object">Magento\Widget\Model\Template\Filter</argument>

Now, in your template you can use this:

<?php echo $block->filterOutputHtml($content);?>

where $content is the content you are trying to interpret as HTML.

| improve this answer | |

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.