Grapesjs: import content dynamically

Created on 25 Nov 2017  路  7Comments  路  Source: artf/grapesjs

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

outdated

Most helpful comment

@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()

All 7 comments

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

@suraj740 ^^

@duskhacker thanks , but i have to edit newsletter so i want to import it dynamically and also i am getting html with inline css getting from remote call. The thing is that i want to call that import function programatically not just by clicking on import button.

@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()

@duskhacker Thanks a lot bro :), its working now.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adam-gpc picture adam-gpc  路  3Comments

ionic666 picture ionic666  路  3Comments

kickbk picture kickbk  路  3Comments

kawika-connell picture kawika-connell  路  3Comments

nojacko picture nojacko  路  3Comments