I am using magento 2.2.2 and I want to add custom variables to the products description.

for now, I can do that with the pages but not for the products (in the page editor there's a button called "insert variable" and it will insert a variable, (e.g: {{customVar code=variable_here}})

but if I tried that in a product description, it doesn't work.

any suggestions?


1 Answer 1


Yes, you can do this from your own module by defining a plugin. Note that the following solution is a workaround.

a) You can define a plugin in etc/frontend/di.xml as follows

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Helper\Output">
        <plugin name="variable" type="Test\Variable\Plugin\Output" sortOrder="1" />

b) Plugin would then define an afterProductAttribute() as follows

namespace Test\Variable\Plugin;

class Output

     * @var \Magento\Cms\Model\Template\FilterProvider
    protected $filterProvider;

     * Constructor 
     * @param \Magento\Cms\Model\Template\FilterProvider $filterProvider
    public function __construct
        \Magento\Cms\Model\Template\FilterProvider $filterProvider
        $this->filterProvider = $filterProvider;

     * Filter outpout of value 
     * @param \Magento\Catalog\Helper\Output $context
     * @param mixed $value
     * @return string
    public function afterProductAttribute(\Magento\Catalog\Helper\Output $context, $value)
        return $this->filterProvider->getBlockFilter()->filter($value);

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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