This will add the variable and widget buttons to the description-field when you're editing a category. But the widgets/variables need to be rendered as well on the frontend, otherwise you would just see the widget tags appear as text on the frontend (this was the question asked by anujeet).
To do this, add a plugin to your etc/di.xml (or etc/frontend/di.xml) with the following:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!--
Plugin to render widgets in category description:
-->
<type name="Magento\Catalog\Model\Template\Filter">
<plugin name="render_widgets" type="Vendor\Module\Plugin\Magento\Catalog\Model\Template\Filter" />
</type>
</config>
And in Vendor\Module\Plugin\Magento\Catalog\Model\Template\Filter.php put:
use Magento\Cms\Model\Template\FilterProvider;
/**
* Class Filter
*/
class Filter
{
/**
* @var FilterProvider
*/
protected $filterProvider;
/**
* Filter constructor.
* @param FilterProvider $filterProvider
*/
public function __construct(
FilterProvider $filterProvider
) {
$this->filterProvider = $filterProvider;
}
/**
* @param \Magento\Catalog\Model\Template\Filter $subject
* @param string $returnValue
* @return string
*/
public function afterFilter(\Magento\Catalog\Model\Template\Filter $subject, string $returnValue)
{
return $this->filterProvider
->getBlockFilter()
->filter($returnValue);
}
}
Best Answer
In case anyone is wondering how to do this in Magento 2.1.x (and probably 2.2+ as well). Here's how:
Create your own custom module and add
view/adminhtml/ui_component/category_form.xml
with (at least) the following code in it:This will add the variable and widget buttons to the description-field when you're editing a category. But the widgets/variables need to be rendered as well on the frontend, otherwise you would just see the widget tags appear as text on the frontend (this was the question asked by anujeet).
To do this, add a plugin to your
etc/di.xml
(oretc/frontend/di.xml
) with the following:And in
Vendor\Module\Plugin\Magento\Catalog\Model\Template\Filter.php
put:That's it! Everything should work now.