Issue #1272πŸ’¬ AnsweredOpened July 10, 2018by Moikapy0 reactions

Using setComponent() ??

Quick answerby artf

https://github.com/artf/grapesjs/issues/1074#issuecomment-405020535

Read full answer below ↓

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, 2019

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins β†’
Premium option

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.

All tutorials β†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.