Issue #571Opened November 25, 2017by suraj7403 reactions

import content dynamically

Question

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

Answers (3)

duskhackerNovember 27, 20172 reactions

@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, 20171 reactions

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, 20170 reactions

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

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.