custom text area wysiwyg attribute product in magento2

by Yogita   Last Updated June 21, 2018 08:09 AM

When I am getting the value of text area type attribute WYSIWYG enabled will not show images or media content in phtml.

I am using below code in my theme's product's addtocart.phtml file:

<?php
$_product = $block->getProduct();
$demoStore = $_product->getResource()-getAttribute('extension_demo_details')->getFrontend()->getValue($_product);
$attr_label_for_demo =$_product->getResource()->getAttribute('extension_demo_details')->getStoreLabel();
?>

<p><?php echo $demoStore; ?></p>

//Will not show media related data



Answers 2


Please try like this one:

<?php
$_product = $block->getProduct();
$demoStore = $this->helper('Magento\Catalog\Helper\Output')->productAttribute($_product, $_product->getExtensionDemoDetails(), 'extension_demo_details');
?>

<p><?php echo $demoStore; ?></p>
Mohit Kumar Arora
Mohit Kumar Arora
June 21, 2018 08:03 AM

Try following way

<?php
namespace Company\Module\Helper;

class Data extends AbstractHelper
{
    public function __construct(
        \Magento\Framework\App\Helper\Context $context,
        \Magento\Cms\Model\Template\FilterProvider $filterProvider
    ) {
        parent::__construct($context);
         $this->_filterProvider = $filterProvider;
    }

    public function getAttribute($text)
    {
        return $this->_filterProvider
            ->getBlockFilter()->filter($text);

    }
}

addtocart.phtml file:

<?php
$_product = $block->getProduct();
$demoStore = $_product->getResource()-getAttribute('extension_demo_details')->getFrontend()->getValue($_product);
$attr_label_for_demo =$_product->getResource()->getAttribute('extension_demo_details')->getStoreLabel();

$helperData = $this->helper('Company\Module\Helper\Data');
?>

<p><?php echo $helperData->getAttribute($demoStore); ?></p>

Using object manager

<?php 
//Get Object Manager Instance
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$filterProvider = $objectManager->get('\Magento\Cms\Model\Template\FilterProvider');

echo $filterProvider->getBlockFilter()->filter($demoStore);
Prashant Patel
Prashant Patel
June 21, 2018 08:37 AM

Related Questions






Check if attribute equals specific value

Updated March 29, 2017 11:09 AM