# Adding the WYSIWYG editor to an extension
While developing the new Fontis Blog extension,
 we wanted to allow use of the same WYSIWYG editor tools that users have when
 creating Magento CMS pages or static blocks. Doing so is not very difficult,
 requiring only a few changes to add the Magento WYSIWYG to your own extensions.

 The first step is tell Magento that it can load the
 TinyMCE WYSIWYG JavaScript file. This should be done in the layout, in the handle
 used for your page, like so:

&lt;reference name=&#34;head&#34;&gt;
    &lt;action method=&#34;setCanLoadTinyMce&#34;&gt;&lt;flag&gt;1&lt;/flag&gt;&lt;/action&gt;
&lt;/reference&gt;

 The second step is to set a couple of attributes for each
 field on your page that you wish to have the WYSIWYG editor. For each
 field that you have on your page, you'll have a call to 
 $fieldset-&gt;addField() with a few configuration
 options. Most fields will have the "name", "label", "title", "style" and "required"
 options set. To enable the WYSIWYG editor for a specific field, you'll need
 to add the following two options:

 wysiwyg &mdash; set this to true

 config &mdash; make a call to Mage::getSingleton(&#34;cms/wysiwyg_config&#34;)-&gt;getConfig()
 and assign the result to this

 This will be enough to get the WYSIWYG editor working, but there are still some
 additional steps required to get it working as you'd expect.

 When you make the call to Mage::getSingleton(&#34;cms/wysiwyg_config&#34;)-&gt;getConfig(),
 you can specify a few defaults. To do so, you create an array with these
 defaults and pass it as a parameter to getConfig(), like so:

Mage::getSingleton(&#34;cms/wysiwyg_config&#34;) -&gt; getConfig(array(
    &#34;add_variables&#34; =&gt; true,
    &#34;add_widgets&#34; =&gt; true,
    &#34;add_images&#34; =&gt; true,
);

 These settings control the visibility of the "Add Variables", "Add Widgets" and
 "Add Images" buttons when the WYSIWYG editor is hidden. It is also worth noting that
 if the WYSIWYG editor is disabled completely, the "Add Images" button will not show
 up even if set to true unless either add_variables or
 add_widgets (or both) are set to true.

 Next, in order for the Magento WYSIWYG image gallery to actually appear, you need to add
 &lt;update handle=&#34;editor&#34;/&gt; to the relevant layout XML.
 For example:

&lt;adminhtml_blog_blog_edit&gt;
    &lt;update handle=&#34;editor&#34;/&gt;
&lt;/adminhtml_blog_blog_edit&gt;

 This tells Magento to load in further JavaScript which enables the use of the gallery.
 You'll need to ensure this is in place for all controller actions, such as for separate
 edit and add actions.

 Lastly, don't forget to put the text the user entered through Magento's CMS processor
 before the text is output to the browser. This ensures the CMS tags inserted by
 the WYSIWYG editor are parsed and replaced by actual markup. This is done with a
 call to the following function:

$processedContent = Mage::helper(&#34;cms&#34;)-&gt;getPageTemplateProcessor()-&gt;filter($unprocessedContent);

 Following the above process should allow your extension to provide admins
 with the familiar Magento WYSIWYG editor on a text field of your choosing, making it easy
 for them to manage rich content on their site.