Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get HTML and CSS from grapes.js newsletter editor in Javascript

How to get output HTML and CSS of grapes.js in Javascript ?

I am writing a Django app for newsletter, in which I need a newsletter editor for which I used "grapes.js" newsletter. Everything is fine but I am stuck in part where I need to get the HTML and CSS of the template created with it.
I have:

<script type="text/javascript">
  var editor = grapesjs.init({
  container : '#gjs',
  plugins: ['gjs-preset-newsletter'],
  pluginsOpts: {
    'gjs-preset-newsletter': {
      modalTitleImport: 'Import template',
    'grapesjs-plugin-export': { /* options */ }
      // ... other options
    }
  }
});
function returnHtml(){ 
    console.log('test')
    const mjml = editor.getHtml;
    preview = editor.getHtml
    $("#myiframe").contents().find("body").html(mjml)
}
returnHtml();

This code gives me the html of the template but without the css !

I have tried https://github.com/artf/grapesjs-mjml/issues/2. Can someone please suggest me what i am missing ? Thanks.

EDIT: I have an answer below but what i need is like this with html and css together like in export HTML.Thanks again. https://screenshots.firefox.com/u752bu0nNN97rXlr/127.0.0.1

like image 964
Ansuman Avatar asked Dec 31 '18 07:12

Ansuman


1 Answers

Getting only HTML:

var html = editor.getHtml();

Getting only CSS:

var css = editor.getCss();

Getting HTML with CSS inline:

var htmlWithCss = editor.runCommand('gjs-get-inlined-html');
like image 54
svalenciano Avatar answered Oct 05 '22 23:10

svalenciano