Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

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?

share|improve this question
    
What do you mean 'in a correct way'? –  oleksii.svarychevskyi Feb 16 at 17:04
    
To get <img src="imagepath/article1.jpg" /> instead of {{media...}}. –  Anthony Feb 16 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? –  oleksii.svarychevskyi Feb 16 at 18:03
    
It doesn't change it) –  Anthony Feb 16 at 18:14
    
Can you please update the question with code of form field definition? –  oleksii.svarychevskyi Feb 16 at 18:15
add comment

1 Answer

up vote 1 down vote accepted

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".

share|improve this answer
    
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 Feb 16 at 20:49
    
If my answer helped you mark it as accepted. –  oleksii.svarychevskyi Feb 16 at 20:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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