Magento 2 – Decode Widget Code in Category Description

categorymagento2static-blockwidget

I have added widget(call static block) in category description http://prntscr.com/ko816y.
But it is not call widget in front just showing output as it look in admin WYSIWYG editor.
So,I want to convert below code to html

{{widget type="Magento\Cms\Block\Widget\Block" template="widget/static_block/default.phtml" block_id="10"}}

enter image description here
How can I convert widget code to html?

EDIT
I have Call Description like this way

<?= /* @escapeNotVerified */ $this->helper('Magento\Catalog\Helper\Output')->categoryAttribute($block->getCurrentCategory(), $_description, 'description') ?>

Best Answer

you need to pass the content of the description inside a function before the display. This filterProvider will replace the widget code inside the content of the description.

public function __construct(
    \Magento\Cms\Model\Template\FilterProvider $filterProvider
)
{
    $this->_filterProvider = $filterProvider;
}

public function addWidget($description) {
     $newDescription = $this->_filterProvider->getPageFilter()->filter(
           $description
     );
     return $newDescription;
}       
Related Topic