Best way to render a page stored in firestore?
Question
I've been reading a lot of the documentation and closed issues but I'm a little confused on the best approach to render a page stored in firestore.
For example I have a node.js backend using cloud functions and i was thinking i would basically have an API endpoint that pulls the page from the firestore and renders it. Is this possible? I haven't found many examples on how to render pages from the server.
In short how can i render a page generated in grapejs? So i can show a preview of the page and also have a live website using something generated by grapejs.
ex:
app.get('/pages/:id', (req, res) => {
const page = firebase.getData(req.params.id); // just an example
res.send(page);
});
Answers (1)
Hi Josh, storing and loading templates is described more in details here: https://grapesjs.com/docs/modules/Storage.html#store-and-load-templates
Basically, the editor stores 2 types of data:
componentsandstyle, JSON result of your template. You need these to load back the data in the editor.htmlandcss, HTML/CSS result of your template. This can be used to be rendered in your final page (eg. the page created by your user) but DON'T use it to load it back in the editor for editing.
In short how can i render a page generated in grapejs?
Well, this depends, I'd expect you to know that at first 😅. For example, if you store the entire object in your firebase document the result might be something like this:
app.get('/pages/:id', (req, res) => {
const page = firebase.getData(req.params.id); // just an example
// Just an example of what you can return
res.send(`<html>
...
<style>${page.css}</style>
</head>
<body>
${page.html}
</body>
<html>`);
});
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2181
global functions/variables
Hello there! recently i noticed this issue. I think it would be beneficial to have this feature. in contrast to the suggested approach by @...
Issue #841
[QUESTION] Add default Trait (attribute) to model for all HTML Components (elements)
Hi, I've read the Traits, Components and API wikis, grepped all the open & closed issues. I've even found the code where you are creating t...
Issue #1167
[QUESTION] export options
Hi @artf, Are there any other export options than HTML/CSS ? I'm thinking of a way to directly load the configuration from a remote server...
Issue #3141
Loading dynamic content
I really apologise if this has been covered previously. I have searched the issues and also read the documentation quite extensively and ma...
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.