[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:
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:
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)
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.
@alikabeer32 Hmm, that seems to have solved the problem. Thanks!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2596
[QUESTION] Add html, css and js to Block Manager
[QUESTION] Hi! I'm retrieving dynamic html,css and js codes from the database. How can I create Blocks with this? Currently, this is my cod...
Issue #3631
How to load dynamic content in the final HTML file?
I looked everywhere, including the issues section and tried a few things. But really unsure how to load dynamic content in my components al...
Issue #2982
BUG: Executing editor.load(x) on x = editor.store() results in error.
Version: 0.16.18 Are you able to reproduce the bug from the demo? [X ] Yes [ ] No What is the expected behavior? I would expect that assets...
Issue #2184
[QUESTION] Losing predefined media queries
Hi. I have a predefined json of a template which contains a set of html elements and styles which are parsed into the set of components upo...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.