Placing non-editable HTML around wrapper
Question
My CMS works like this: sites can have one theme and many templates under that theme. Themes are rendered on every page, and templates are rendered only on specific pages. I have successfully integrated GrapesJS with my existing template editor, but I have a question: is there any way to render a theme around a template in Grapes? That is, is there any way to insert non-editable HTML around the editable HTML? If I place HTML in the canvas between the body and the #wrapper, I seem to get the result I want.
Is there an existing API for achieving this, and if not, is this desirable functionality or am I better off using JavaScript to inject my theme HTML into the editor?
P.S. First post here. Great work on this software @artf . I am excited to see how Grapes can help me and how I can contribute to this project.
Answers (3)
I've fiddled with the code and made a small patch that fits my needs. A config option surround lets you specify an ID, which represents an element in the container. This DOM subtree is plucked out during the main initialization, stored in the Editor config, and picked up by the Canvas. The Canvas then handles rendering of the surround around the wrapper. I am interested to know if anyone else has needs like this and if this seems like a good solution.
Again, if the use case isn't clear: suppose I am using Bootstrap, and I have a Theme with a container, navbar, footer, etc. I then have a page Template which I am editing with Grapes. I want to see the Template inside its Theme's HTML, but I should be able to edit only the Template, and similarly Editor.getHtml() should return only the Template HTML.
Greate @z1lk I think even something like this will work
const canvas = editor.Canvas;
const surround = document.createElement('div');
surround.innerHTML = '<div>Some text</div>';
canvas.getBody().appendChild(surround);
surround.appendChild(canvas.getWrapperEl());
I close this as you've solved your case
I used a solution similar to yours so I don't have to maintain changes to the Grapes source. Sometimes the position of the component "tools" are out of place, as if their vertical offset is computed relative to the body and not the wrapper. I can't reliably reproduce it though. Thanks for your help @artf
edit: I think the tools misplacement was due to the "surround" moving from outside the canvas to inside. I no longer have the problem, but I can produce a similar issue by selecting a component to bring up the tools and then opening up my browser's inspector (Firefox). Similar to #495
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1770
[Bug] Components with custom tag are not rendered if specified in theme body
Hello I created very simple skeleton of GrapesJS editor. HTML template: Javascript: Result of loading: As you see, component is not rendere...
Issue #577
Only allow one component of specific type on editor
is there way to not allow to drop any specific component more than one time on page? I have custom component and user cannot drop it more t...
Issue #1942
HTML conditional comments could not be loaded while we edit the template
While editing the template, conditional comment removed by auto rendering but works when we try to import and save
Issue #1817
Change HTML content while block is render in editor
Hello @artf I have one block into block manager like As per above script inside the block, i want to add dynamic HTML content while this bl...
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.