2

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') ?>
  • 2
    Can you explain how can call description for the category? – Prince Yadav Sep 3 '18 at 9:03
  • 1
    may I know Magento 2 version? – kunj Sep 3 '18 at 9:24
  • It's 2.2.2 version I have update my Question – Ketan Borada Sep 5 '18 at 6:23
3

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;
}       
1

I don't know why it doesn't work for you, basically {{widget type="Magento\Cms\Block\Widget\Block" template="widget/static_block/default.phtml" block_id="10"}} should work in cms page, category descriptions etc...

I have some workaround, it is not very best way but try it:

  1. Create phtml in : app/design/frontend/{Vendor}/{theme}/Magento_Theme/templates/html/category-description.phtml

    <?php echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId("static-block-indentifier")->toHtml(); ?>
    
  2. In your category description area >Wysiwyg editor > show/hide editor > add this:

    {{block class="Magento\Framework\View\Element\Template" template="Magento_Theme::html/category-description.phtml"}}
    

Now you should get your static-block content in your category description.

  • please check my question again i called widget for call static block you have put it directly.non technocal user can not call static block directly as you have did – Ketan Borada Sep 10 '18 at 6:54
  • I didn't understand your comment, non technocal user can not call static block directly ? Why I can't call a static-block directly ? you mean this <?php echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId("static-block-indentifier")->toHtml(); ?> whats wrong here ? – PЯINCƏ Sep 10 '18 at 7:56
  • I want to decode widget in category description you have call static block by fix Identifier.It is not neceessary to call only static block from widget there are many functionality within widget. prntscr.com/ksmilu it is not only for static block – Ketan Borada Sep 10 '18 at 9:24
  • I want to decode all these things in front-end prntscr.com/ksmjqd . prnt.sc/ko816y – Ketan Borada Sep 10 '18 at 9:27

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.