2

I found so many articles about how to use wysiwyg editor in admin pages, and I was wondering if I could use it in the frontend templates. if yes, please tell me how. I'm using magento 2.1.5.

6

In frontend suppose we want wysiwyg-editor on a textarea and textarea having id : description

<textarea id="description" name="textarea_name"></textarea>

and use below script to load jquery and wysiwyg tiny_mce and assign to #description

require([
        'jquery',
        'mage/adminhtml/wysiwyg/tiny_mce/setup'
    ], function(jQuery){

    var config = '', 
        editor;

    jQuery.extend(config, {
        settings: {
            theme_advanced_buttons1 : 'bold,italic,|,justifyleft,justifycenter,justifyright,|,',
            theme_advanced_buttons2: null,
            theme_advanced_buttons3: null,
            theme_advanced_buttons4: null,
            theme_advanced_statusbar_location: null
        },
        files_browser_window_url: false
    });
    editor = new tinyMceWysiwygSetup(
        'description',
        config
    );
    editor.turnOn();
    jQuery('#description')
        .addClass('wysiwyg-editor')
        .data(
            'wysiwygEditor',
            editor
        );
});

As per your's need you can update wysiwyg tiny_mce configuration. above one just an example.

  • It is not working in my case..I tried the same ... – Manish Goswami Oct 5 '17 at 12:28
  • @ManishGoswami can you share your logic so i can check, by the way what is not working in this code that also mention so i can help you easily. – Kanhaiya lal Oct 6 '17 at 10:36
  • it is loading the tiny_mce in my case, but the editor area is not clickable, i am not able to put any data. – Deepak Kumar Nov 2 '17 at 10:11
  • @DeepakKumar click at the top left corner of editor in text area , you will get cursor pointer. once you get pointer you can enter you text or data. – Kanhaiya lal Nov 6 '17 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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