6

I have a wysiwyg custom attribute.

Insert an image there: enter image description here

But in the html code source I see this one:

<img src="{{media url="wysiwyg/article1.jpg"}}" alt="" />

Instead of

<img src="imagepath/article1.jpg" alt="" />

This html source is generated by this code:

<?php echo $_item->getPreview() ?>

Why wysiwyg cms directive was not replaced with image url?

5
  • What do you mean 'in a correct way'? Commented Feb 16, 2014 at 17:04
  • To get <img src="imagepath/article1.jpg" /> instead of {{media...}}.
    – Anthony
    Commented Feb 16, 2014 at 17:23
  • That is how magento wysiwyg works. During output '{{media url="wysiwyg/article1.jpg"}}' will be changed to 'imagepath/article1.jpg'. So what is your exact problem? Commented Feb 16, 2014 at 18:03
  • It doesn't change it)
    – Anthony
    Commented Feb 16, 2014 at 18:14
  • Can you please update the question with code of form field definition? Commented Feb 16, 2014 at 18:15

3 Answers 3

7

Custom attribute with wysiwyg cannot be simply outputted.

If it contains cms directives {{media url="wysiwyg/images_2_.jpg"}}, it should be preprocessed with catalog/output helper.

<?php
    $product = $this->getProduct();
    $attribute = $product->getYourAttribute();
    $attributeName = 'your_attribute_name';
    echo $this->helper('catalog/output')->productAttribute($product, $attribute, $attributeName);
?>

Important

Check that in sql upgrade your custom attribute was created correctly with all necessary properties

$this->addAttribute('catalog_category', 'custom_attribute', array(
    'group'                    => 'General',
    'input'                    => 'textarea',
    'type'                     => 'text',
    'label'                    => 'Custom attribute',
    'backend'                  => '',
    'visible'                  => true,
    'required'                 => false,
    'visible_on_front'         => true,
    'global'                   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'wysiwyg_enabled'          => true,
    //these attribute is very important for processing cms directives
    'is_html_allowed_on_front' => true,
));

Also make sure that "Allow Dynamic Media URLs in Products and Categories" in System->Configuration->Catalog->Frontend is set to "yes".

1
  • 1
    Yes, you are right. I didn't write that attribute is like cms page attribute. It's not for catalog entity. So I found an answer: <?php $helper = Mage::helper('cms'); $processor = $helper->getPageTemplateProcessor(); $html = $processor->filter($_item->getPreview()); ?>
    – Anthony
    Commented Feb 16, 2014 at 20:49
2

Use helper class

Instead of <?php echo $_product->getDescription();?>,

use <?php echo $_helper->productAttribute($_product, nl2br($_product->getDescription()), 'description'); ?>.

For me, its solved same issue on magento version 1.8.

0

For Magento 2.2.3 Please check that attribute you want to display meet the conditions: $attribute->getIsHtmlAllowedOnFront() $attribute->getIsWysiwygEnabled()

This check present in vendor\magento\module-catalog\Helper\Output::productAttribute

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.