How to Add WYSIWYG Editor in Magento 2 Admin Form
WYSIWYG is an HTML editor to easily play with the content editing. WYSIWYG allows adding and formatting the content providing “What You See Is What You Get ” view. One can see the end result that’ll be displayed in the editing phase. Save yourself from the hassle of HTML programming for enhancing the appearance of frontend!
Magento 2, designed to be as user-friendly as possible, has WYSIWYG as the default editor. ? But sometimes, you need to add WYSIWYG editor in Magento 2 Admin Form to collect data.
Adding WYSIWYG editor in Magento 2 backend eases the task of website development. What more luxury does a developer wish for? ?
So, here’s the code for you, ready to be implemented in the admin backend!
Code to Add WYSIWYG Editor in Magento 2 Admin Form:
Add the following code in your block file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
protected $wysiwygConfig; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig, array $data = [] ) { $this->wysiwygConfig = $wysiwygConfig; parent::__construct($context, $data); } Add field code $fieldset->addField( 'content', 'editor', [ 'name' => 'content', 'label' => __('Body'), 'title' => __('Body'), 'rows' => '5', 'cols' => '30', 'wysiwyg' => true, 'config' => $this->wysiwygConfig->getConfig(), 'required' => true ] ); |
Follow the above method and the content editing is as easy as ABC!
If you face any problem in adding WYSIWYG editor in Magento 2 Admin Form, please mention it in the comments section below and I’ll help you out 🙂
Rate the post with 5 stars if found useful.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How to Add Top Link in Magento 2
How to Stop Spam Registrations in Magento 2
Next