[QUESTION] Using setComponent() ??
Question
Creating a Plugin to use GrapesJS with Plone. GrapesJS Version: Latest
When using the setComponent() function, we are scraping the HTML content from one page and setting it as the content for GrapesJS to edit/manipulate. The Component is then dropped into the Canvas along with the data-gjs-* attributes are applied and carried over when saved to our page, but when pulling the same page back into GrapesJS they seemed to have been removed after being passed through the setComponent() function.
The console.log() prior to the setComponent() seems to log the elements as intended with the data-gjs-* attributes applied.
How we are getting the out page content:
//
,$.get(url).done(function(data) { //Get page content
//Get base url, which is the dirrect url to the page without any redirrects
base = data.substring(data.indexOf("<base"), data.length);
base = base.substring(base.indexOf("href") + 6, base.indexOf('/>') - 2);
//Parsing local css from the data returned
css = data.substring(data.indexOf("/* Local CSS from"), data.length);
css = css.substring(css, css.indexOf("</style>"));
//Parsing the html content from the data returned
htmlContent = data.substring(data.indexOf("parent-fieldname-text"), data.length);
htmlContent = htmlContent.substring(htmlContent.indexOf(">") + 1, htmlContent.length);
htmlContent = htmlContent + "<div>";
htmlContent = htmlContent.substring(htmlContent, htmlContent.indexOf("viewlet-below-content-body") - 25);
htmlContent = htmlContent.substring(htmlContent, htmlContent.lastIndexOf("</div>"));
//Setting the css, and html compontnets.
console.log(htmlContent);
editor.setComponents(htmlContent);
editor.setStyle(css);
});
Answers (2)
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1912
[QUESTION] Custom component default children
Hi, I am trying to understand how I can achieve the following.Create a component with a default content as children.Create a block to add t...
Issue #1289
data-gjs-custom-name question
I've created a simple block content with a custom data-gjs-custom-name = "test". When i save the page i cant see those attributes on the ge...
Issue #1401
help for create component
Hello, I need to do two things:I need a component to create a button with specifically id and disabled edit the id.Define one tag HTML impo...
Issue #1895
[QUESTION] Drag component over canvas with script, script appended multiple times.
Hi, not sure if this is a bug or not. But I noticed a weird behavior, when I drag a block that has a component that contains a script funct...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.