Save to db data-gjs-droppable
@ghena you should store HTML/CSS for the final result, for the editor you have to rely on JSON format I think it would be better for you using the built-in remote storage instead of a custom one Check also #597
Read full answer below ↓Question
Hi guys,
I need to solve a problem. Saving html grapejs strip all data-gjs-* from html. Exists a way to maintain all data-gjs-* before save editor html ?
Infact if i save my template all data-gjs-droppable is missing and in a next render it doens load data-gjs-droppable attributes and son on.
I save in this way:
editor.Commands.add
('save-db',
{
run: function(editor, sender)
{
//var html = editor.runCommand('gjs-get-inlined-html');
var html = editor.getHtml();
var css = editor.getCss();
var customBlocks = $($.parseHTML(html)).find('.custom-block');
var post_ids = [];
var params = {css:css,html: html,post_id:<?php echo $_post->ID ?>};
jQuery.ajax(
{url: '<?php echo $pathHttpGrapes ?>/scripts/save.php',
type: 'POST',
data: params,
dataType: "json",
crossDomain: false,
success: function(result){
},
error:function(){
toastr.error("Si è generato un errore inatteso");
}
});
sender && sender.set('active'); // turn off the button
}
});
thanks in advance.
regards.Answers (3)
@ghena you should store HTML/CSS for the final result, for the editor you have to rely on JSON format
const comps = editor.getComponents();
const style = editor. getStyle();
I think it would be better for you using the built-in remote storage instead of a custom one
grapesjs.init({
...
storageManager: {
type: 'remote',
stepsBeforeSave: 10,
contentTypeJson: true,
urlStore: "<?php echo $pathHttpGrapes ?>/scripts/save.php",
// You don't need this if you already init the editor with a template
// autoload: true,
// urlLoad: "/load-template/2",
params: {
post_id: <?php echo $_post->ID ?>
},
},
})
Check also #597
@artf how to save with remote end point with inlined html mode , i mean html and css into html sent to server ? thanks
@shareefhiasat all you need is here https://github.com/artf/grapesjs/wiki/Storage
Related Questions and Answers
Continue research with similar issue discussions.
Issue #892
How to get the link value?
Hi Guys, How can I get all links value before or upon saving the email template. I want to substitute the links with proxy url. In order to...
Issue #1124
Style is not copying after cloning the element
Hi @artf. At the first time before saving the template, When I make one element and clone it, the style is coming in the clonned element. T...
Issue #1875
[QUESTION] ID changes when importing html or passing html in components prop in config.
Hi, I built a component and block that I can drag and drop in the canvas. My issue is that some styles rely on the ID. I know this might no...
Issue #1960
[QUESTION] Dynamic class generation with a template
Hi there ! I am wondering if there is a way to force the dynamic class generation (of the form cXXXXX which happens when I drag'n'drop a co...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.