Replies: 13 comments 13 replies
-
Maybe you could install grapesjs server-side(similar to client-side) and use it for rendering, otherwise you'll have to reverse engineer the renderer. Another alternative would be to store the generated HTML in the database as well. |
Beta Was this translation helpful? Give feedback.
-
Well, I think that would be cool but unfortunately, at the moment, we leak a lot of DOM interfaces at the initialization level. So, it might be possible if you're ok with using something like |
Beta Was this translation helpful? Give feedback.
-
+1 need ssr feature so much, can't live without |
Beta Was this translation helpful? Give feedback.
-
Hello, For future questions or technical issues, which aren't bugs, GitHub's Discussions tab is the place to be. Don't forget to close this issue if it is resolved or write a new detailed message in Discussions -> Q&A category (and close this issue). Thank you for your understanding. |
Beta Was this translation helpful? Give feedback.
-
Note that the exported HTML retrieved via |
Beta Was this translation helpful? Give feedback.
-
@anlumo, unfortunately, grabbing iframe content is not good as each component can have a completely customized view. I mean, it might work for your case but for sure it's not a stable approach. |
Beta Was this translation helpful? Give feedback.
-
Yes, if you have any kind of interactive content, that probably wouldn't work. Fortunately that's not the case for my application. |
Beta Was this translation helpful? Give feedback.
-
Just a quick update, I've merged the first iteration of the You can check the related test case here which illustrates also some of the examples of usage. I guess the final goal would be to give the possibility to load, edit and store the JSON file by using the same API and, as you can see from the test file, it should already be possible (but I didn't play that much I'd say). const editor = grapesjs.init({ headless: true });
const jsonData = await loadProjectData(projectID); // { pages: [...], styles: [...], ... }
editor.loadData(jsonData);
const mainPage = editor.Pages.getMain();
const wrapper = mainPage.getMainComponent();
// note: can't use `.find` method, as it requires DOM API
wrapper.findType('image').map(img => img.set('src', 'placeholder.jpg'));
const newData = editor.storeData();
await storeProjectData(projectID, newData); @AdamTorma In case of your initial question, you would do something like this const editor = grapesjs.init({ headless: true });
const components = editor.addComponents({ type: '...' }); // Component Definition
const html = components.map(cmp => cmp.toHTML()).join(''); At the moment is not possible to use all those methods which would require the use of some DOM API (without using something like I'll move this issue in a Discussione so for any further update related to the subject, can be discussed there. |
Beta Was this translation helpful? Give feedback.
-
Hi @artf thank you for this work! I'm trying to get grapesjs to render our HTML on the server. This is what my code looks like:
In my package.json I added:
However, I keep running in this error:
Do you have any tips on how to solve this? I have tried building Thanks in advance! |
Beta Was this translation helpful? Give feedback.
-
@koendeschacht just added your example here as a test and works as expected. |
Beta Was this translation helpful? Give feedback.
-
can you refer me to some sample code to use grapesjs In nodejs @artf |
Beta Was this translation helpful? Give feedback.
-
Hey @artf, let me start by saying: thanks for your awesome package and for adding a headless option to it! However, I'm struggling to get GrapesJS to work server-side. I've read your thread with Koen and tried to reproduce it to the best of my abilities, but without success. In short: when I add
Stacktrace, for what it's worth``` ReferenceError: document is not defined at Module. (/Users/yoeri/Development/node-grapesjs/node_modules/grapesjs/dist/grapes.min.js:2:103296) at n (/Users/yoeri/Development/node-grapesjs/node_modules/grapesjs/dist/grapes.min.js:2:412) at Module. (/Users/yoeri/Development/node-grapesjs/node_modules/grapesjs/dist/grapes.min.js:2:596611) at n (/Users/yoeri/Development/node-grapesjs/node_modules/grapesjs/dist/grapes.min.js:2:412) at /Users/yoeri/Development/node-grapesjs/node_modules/grapesjs/dist/grapes.min.js:2:1214 at /Users/yoeri/Development/node-grapesjs/node_modules/grapesjs/dist/grapes.min.js:2:1225 at /Users/yoeri/Development/node-grapesjs/node_modules/grapesjs/dist/grapes.min.js:2:81 at Object. (/Users/yoeri/Development/node-grapesjs/node_modules/grapesjs/dist/grapes.min.js:2:203) at Module._compile (internal/modules/cjs/loader.js:1063:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) ```I created a minimal repo that produced the same result. The steps were:
I pasted in Koen's example code in
which produces the above mentioned results. Any idea what I'm doing wrong here? |
Beta Was this translation helpful? Give feedback.
-
Hi @artf, thank you for all the work on the grapesjs framework and thanks a lot for the headless option. We were migrating our custom editor layout on to the grapesjs editor experience and used the headless option to build the editor using the existing components, which are added as custom components in grapesjs using plugins. While adding the plugin for custom components in the grapesjs.init() call, we ran into a DOM call which broke the editor initialization. The error seems to be from src/index.js Shouldn't we have a check here? Something like PS: Adding the plugins in the editor initialization as named-plugins seems to be a work-around here and works in our case. |
Beta Was this translation helpful? Give feedback.
-
So first of all, thank you @artf for this amazing project.
I have a question:
Is it possible to easily convert the components-JSON to HTML on the server-side (in a Node.js environment)? If it is possible, can you give me a hint how to achieve this?
On the client-side it's quite straightforward:
I can get the components-JSON (
JSON.stringify(editor.getComponents());
) and save it to my database. Then I can reuse my components later (editor.setComponents();
) and get the HTML (editor.getHtml();
) to show it in the browser. In my case though, I have to do it on the server-side.Any help would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions