GrapesJS / mjml

Newsletter Builder with MJML components in GrapesJS
http://grapesjs.com/demo-mjml.html
BSD 3-Clause "New" or "Revised" License
624 stars 222 forks source link

grapesjs - mjml: how do I get the html? #66

Closed cazcoder closed 4 years ago

cazcoder commented 6 years ago

Hi, I'm new to grapes.js and am using the mjml plugin but can't figure out how to get the html. I want to save the html to the database when a save button is clicked on. A previous post said I must use editor.runCommand('mjml-get-code').html but it gives 'undefined' as the result. My code is the following:

var editor = grapesjs.init({ height: '100%', noticeOnUnload: 0, storageManager:{autoload: 0}, container : '#gjs', fromElement: true, plugins: ['gjs-mjml'], pluginsOpts: { 'gjs-mjml': {} } });

  editor.Panels.addButton
      ('options',
        [{
          id: 'save-db',
          className: 'fa fa-floppy-o',
          command: 'save-db',
          attributes: {title: 'Save Newsletter'}
        }]
      );

  // Add the command
  editor.Commands.add
    ('save-db',
    {
        run: function(e, sender)
        {
          sender && sender.set('active', 0); // turn off the button
          e.store();

          var mjmldata = e.getHtml();
          var cssdata = e.getCss();

          var htmldata = e.runCommand('mjml-get-code').html;

          //to do - post to db

        }
    });

Any help would be much appreciated, thank you!

lajuffermans commented 6 years ago

Same here since grapesjs 0.14.9.

runCommand('mjml-get-code').html is working fine in 0.13.8

DRoet commented 4 years ago

editor.runCommand('mjml-get-code') seems to be working fine in the latest version

teatalay commented 1 year ago

Any code did not work for me. I found it from source code

editor.runCommand('mjml-code-to-html')?.html