Issue #1272Opened July 10, 2018by Moikapy0 reactions

[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)

lock[bot]September 17, 20190 reactions

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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.