Issue #571✓ SolvedOpened November 25, 2017by suraj7403 reactions

Import content dynamically

快速解答by duskhacker2

@suraj740 editor.setComponents() will take both html/css, so you could just skip the setStyle call. As for the rest, you did look at the storage manager documentation, yes? You can call load/store on it programmatically without clicking a button, like editor.store(); editor.load()

Read full answer below ↓

Question

Hi @artf , how can i import content dynamically from program that automatically reflect in canvas.

Answers (3)

👍 Most helpfulduskhackerNovember 27, 2017

@suraj740 editor.setComponents() will take both html/css, so you could just skip the setStyle call. As for the rest, you did look at the storage manager documentation, yes? You can call load/store on it programmatically without clicking a button, like editor.store(); editor.load()

duskhackerNovember 27, 2017

In my project, I set data- attributes on an HTML element and extract them via .dataset in Javascript, once the editor is configured, I run:

editor.setComponents(dataSet.legacyHtml);
editor.setStyle(dataSet.legacyCss);
editor.store();

Be aware that the HTML must be set up so that grapesjs can understand it. I believe that it must adhere to the BEM(http://getbem.com/) standard. In practice, I just created a few documents to understand what it's supposed to look like.

Also, it doesn't matter where you get the HTML/CSS, it could be a remote call or just embedded in the Javascript, I just mentioned what I was doing as an example.

HTH

duskhackerNovember 27, 2017

@suraj740 ^^

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.