1

I have custom module field code is bellow for wysiwyg field:-

 $wysiwygConfig = $this->_wysiwygConfig->getConfig(['tab_id' => $this->getTabId()]);
    $fieldset->addField(
                'news_content',
                'editor',
                [
                    'name' => 'news_content',
                    'label' => __('Long Description'),
                    'title' => __('Long Description'),
                    'style' => 'height:11em',
                    'required' => true,
                    'disabled' => $isElementDisabled,
                    'config' => $wysiwygConfig
                ]
            );

when i upload image in this field with content it only shows content and image is not come with proper tag as bellow:-

<p><img src="{{media url="wysiwyg/24.png"}}" alt="" /></p>
<p>test</p>

so there is a question that content filter we used in 1.9.X.X is not in magento 2.0.2.

how can i get image and description from wysiwyg editor with default filter to display image with content.

2
  • where you are using this???
    – Asish Hira
    Commented Apr 6, 2016 at 10:09
  • using in admin edit page Custom\News\Block\Adminhtml\Items\Edit\Tab\Main.php Commented Apr 6, 2016 at 10:14

2 Answers 2

2

Use below code:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$objectManager->get('\Magento\Cms\Model\Template\FilterProvider')->getBlockFilter()->filter($item->getContent());

In above code $item->getContent() is your editor content

1
  • Exactly what i was looking for. Commented Sep 1, 2016 at 10:49
1

Use this code:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Filter\Template')->getTemplateProcessor()->filter($attributeHtml);

Where $attributeHtml should be the content of editor.

10
  • it gives error Undefined property: Magento\Catalog\Helper\Output::$_getTemplateProcessor any solution for that. Commented Apr 6, 2016 at 10:42
  • I update my answer please check this now! and let me know
    – Asish Hira
    Commented Apr 6, 2016 at 10:47
  • it gives blank page. Commented Apr 6, 2016 at 10:50
  • Do you use echo $product ??
    – Asish Hira
    Commented Apr 6, 2016 at 10:51
  • no but did not load page Commented Apr 6, 2016 at 10:52

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.