Issue #2118Opened July 5, 2019by lajby951 reactions

[Question] Save configuration of dynamic blocks into HTML? (Countdown, Slider)

Question

I am trying to save the template data into the database. Currently I have it working successfully. It posts the Assets, Components, Styles, Html, and CSS data (just like how it saves into the browser's localStorage) to a PHP script.

As I found out, the Components part ( editor.getComponents() ) contains the Html structure with all data of dynamic elements which are not static on the page (like Countdown or Slider), so it is reliable for storing the complete template with all dynamic elements. The Html part ( editor.getHtml() ) can only save the static part of the page, it leaves out these dynamic elements.

My problem is that I need a way to store the configuration and initialization code of these dynamic elements (Countdown, Slider) in the Html only. The reason is that after I save all five elements of data (assets, components, styles, html, css) into database, there will be parts of our webpage where I will need to load the HTML and CSS data into an HTML element without relying on GrapesJS (because the template will be shown to end users). The HTML/CSS parts contain the static information, but as of my current knowledge, GrapesJS would need to be initialized to load the Components part.

So maybe one solution would be to load GrapesJS editor and set it up to load the Components part from database and only show the end result (like the preview button) without the ability to edit. But that is not a clean solution, and I would rather avoid initializing GrapesJS just to show the end user the template. I need a better way to do this. Thank you.

Screenshots for explanation: Loading Components and Styles from database to editor: GrapesJS load Components and Styles After this, the Countdown counts down as it should, and the Slider's arrows work as expected.

Loading HTML and CSS from database to editor: GrapesJS load HTML and CSS After this, the Countdown numbers are not showing and the Slider's arrows do not do anything.

I hope you understand the question.

Answers (2)

alikabeer32July 6, 20191 reactions

Is your javascript code actually getting set? It might be because the framework, by default, doesn't set js when you run editor.setComponents(yourhtml);

const editor = grapesjs.init({ ... allowScripts: 1, });

this might help you. All the best.

lajby95July 8, 20190 reactions

@alikabeer32 Hmm, that seems to have solved the problem. Thanks!

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.