0

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

2 Answers 2

4

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>
0

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);

Your Answer

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

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