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.
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With