0

Hi I have a problem with passing an image to a view via WYSIWYG editor. I add the image in the editor, it displays correctly in the editor. Its structure is <img src="{{media url='wysiwyg/technologies/file.png'}}". />, which is, as you can see, the correct notation. After saving the product, the image does not display on the page, and checking devtools I see that I have exactly that string there, i.e. <img src="{{media url='wysiwyg/technologies/file.png'}}" />, while the correct path should be substituted into src there.

Now I'm wondering this because I have a .phtml file that contains so much (it gets this information from this editor), and I'm thinking maybe it's taking literally what's typed there, instead of converting it to the correct path?

<?php

$product = $block->getProduct();
echo $product->getData('technologies');

?>

Anyone encountered something like this?

2 Answers 2

0

You can try setting the image as follows:

$productImageAttr = $_product->getCustomAttribute( 'technologies' );
$productImage = $this->helper('Magento\Catalog\Helper\Image')
    ->init($_product, 'technologies')
    ->setImageFile($productImageAttr->getValue());
0

Try below code. If you need to return a product URL it should look like this:

//todo get product object $product 
$productImageAttr = $_product->getCustomAttribute( 'technologies' );
$objectManager =\Magento\Framework\App\ObjectManager::getInstance();
$helperImport = $objectManager->get('\Magento\Catalog\Helper\Image');

$imageUrl = $helperImport->init($_product, 'technologies')
                ->setImageFile(productImageAttr) // image,small_image,thumbnail
                ->resize(380)
                ->getUrl();
echo $imageUrl;

If any query let me know.

THANKS.

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.