Create the canvas from a URL
That's a real shame. I didn't say anything about fetching from another site, what I wanted to do was keep it consistent with the rest of the project. Oh well, I'll keep looking elsewhere for an editor that integrates better with the current way larger application are built. Webpack and other transpilers really are the...
Read full answer below ↓Question
I've been playing with GrapesJS and trying to integrate it into a Symfony 5 project. In particular I want to be able to edit templates in the editor based on Bootstrap 4 and other components like FontAwesome Pro and custom blocks based on these.
I use Symfony's Webpack-Encore bundle to generate the scripts and style files for the application which leads one heck of major headache trying to get the current iframe canvas system to work using the same versioned components like Bootstrap etc.
Currently I can only inject style and script URLs into the canvas via the init configuration like so:
grapesjs.init({
...
canvas: {
styles: [url1, url2, ...],
scripts: [url3, url4, ...],
},
});
The problem is that I want to keep exactly the same version of included components as I am using in the main application. If I upgrade these I want it to be reflected in the components used by the canvas, this may also include custom code and styles.
In Symfony, and other major frameworks, it's really not good practice to link to root resources outside of the public area, they are generally created and compacted into the public area during a build process.
Webpack creates build files in different ways for different circumstances. In development mode they are served form a local hot-plug server, in production mode from static build files that may or may not include versioning in the file name. Plus the common code can be split out to reduce overhead. You generally reference the files you need using an entry name, this then pulls in as many files as required from the webpack build structure.
Essentially it's a total pain in the rear trying to pick through this to get to the root files needed for a particular view which will likely be very different on the next build.
I would like to propose that we could optionally provide a URL as the base document for the iframe. In this case GrapesJS would load the iframe using the URL and then replace the entire body content, or the contents of an element specified by an id. The latter in many ways is preferable as script elements can then be appended to the bottom of the body element.
This would allow a view, in Symfony or whatever framework, to be created that pulls in whatever files are required and mangled via webpack, thus providing a nice and straightforward way of providing whatever support libraries are needed within the iframe using exactly the correct versions as the rest of the application.
This is not just an issue with Symfony. Any application using a Javascript and CSS compilation and reduction system is likely to suffer the same headaches.
Answers (3)
That's a real shame. I didn't say anything about fetching from another site, what I wanted to do was keep it consistent with the rest of the project.
Oh well, I'll keep looking elsewhere for an editor that integrates better with the current way larger application are built. Webpack and other transpilers really are they way forward for larger projects, even small benefit too.
Hi Ian, if you need to load HTML content from a URL I can only suggest fetching it server-side and initialize the editor with that content (loading external resources in the browser would mostly hit the cross-origin issue), so, for how browsers work I don't see any good reason in adding such a feature.
Thanks for reporting this, @ianef.
Great suggestion about FEAT: Create the canvas from a URL! While this specific feature isn't yet in the core API, there are several ways to achieve similar behavior.
Using the event system:
editor.on('component:update', (component) => {
// your logic here
});
Alternative approaches:
- Listen to
selector:addfor CSS selector changes - Use
selector:customfor custom rules - Tap into the
change:*events for fine-grained tracking - Build a plugin that extends the editor with this capability
Making it official: If this feature would benefit many users, consider opening a formal Feature Request on the GrapesJS repo with:
- A detailed use case
- Code example showing the desired behavior
- Why this matters for your workflow
The core team is receptive to well-motivated feature requests backed by real use cases.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3699
Cell hovering randomly displaces from actual cell
Hi! I'm using grapesJs for e-mail editing in a project in my company, with Newsletter plugin. Everithing works very well, except for this b...
Issue #3345
Panels and Buttons section of getting started not working with Vue.js
I am working to get grapejs to work with Vue.js and am having no luck, I am following the getting started however I am unable to get it to...
Issue #3575
grapes.min.js:2 Uncaught TypeError: Cannot read property 'length' of undefined
I got this error when add the <iframe src="https://app.conversiobot.com/boot/fvMEvO" width="100%" height="500" frameBorder="0" allow="geolo...
Issue #3449
Switching pages calls canvas styles and scripts again and again
Hi I am integrating page manager into my project. But the issue I am facing is that whenever I switch between pages it loads CSS and script...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
GrapesJS Inline RTE Plugins Update: CKEditor 5 v0.1.4 and Froala Inline Text Editor
CKEditor 5 Inline for GrapesJS v0.1.4 fixes Studio SDK toolbar clipping, iframe injection and link balloon bugs. Compare with Froala Inline — both $69.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.