load local html file into grapesjs
Question
hello i am pretty new to grapejs i want to load a local html file in the assets folder into grapesjs editor ,pls tellme how i can load local html file thanks in advance ..
here is my code
----------------------------
import grapesjs from 'grapesjs';
import 'grapesjs/dist/css/grapes.min.css';
import 'grapesjs-preset-newsletter/dist/grapesjs-preset-newsletter.css';
import 'grapesjs-preset-webpage/dist/grapesjs-preset-webpage.min.css';
import gjspresetnewsletter from 'grapesjs-preset-newsletter';
import gjspresetwebpage from 'grapesjs-preset-webpage';
export default {
data() {
return {
editor: null
}
},
methods: {
change() {
this.$emit('change', this.editor.getHtml());
},
},
mounted() {
const LandingPage = {
html: '../userpage/index.html',
css: ['../userpage/style.css','../userpage/css.css','../userpage/bootstrap.min.css'],
components: null,
style: null,
};
this.editor = grapesjs.init({
container: "#gjs",
canvas: {},
fromElement: true,
components: LandingPage.components || LandingPage.html,
style: LandingPage.style || LandingPage.css,
plugins: [],
pluginsOpts: {
"gjs-preset-webpage": {}
},
storageManager: {
type: 'local',
stepsBeforeSave: 10,
urlStore: '',
urlLoad: 'https://raghuv9.github.io/Tapmusic/',
params: {}, token
headers: {},
}
});
}
}Answers (3)
hi! beside reading the content of the file that heavily depends on your environment, (if you are in a node environment you can use 'fs' module), you can use editor.setComponents('your html content'). more info here cheers.
Browser (GrapesJS is executed in browser) should not be able to access arbitrary file from host machine file system. If that was allowed, you would be able to add some JS to a web page and be able to steal files from your users. If you want to achieve this, you must host your files on a http server.
hi! beside reading the content of the file that heavily depends on your environment, (if you are in a node environment you can use 'fs' module), you can use editor.setComponents('your html content'). more info here cheers.
No actually i'm trying to give the link of that html file like url:'../somefolder/test.html' this is how i want to load it into editor instead of pasting html code inside set-component method, is there any chance of doing it like this(urlLoad:"assets/folder/file.html") by using urlLoad method inside storagemanager?
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2262
blocked by cors policy No 'Access-Control-Allow-Origin' header is present on the requested resource
hello i'm using grapesjs with vue wrapper i'm unable to load a webpage using urlLoad: of grapesjs im facing cors issue,i'm pretty new to gr...
Issue #2265
able to fetch my local html file using load url and getting status ok how can i load this fetched url into editor currently im getting blank screen inside editor
here is my code const LandingPage = { html: '', css: null, components: null, style: null, }; this.editor = grapesjs.init({ container: "#gjs...
Issue #1652
In React How to give local css path for grapesjs editor ?
As I am working in Reactjs with grapesjs, I want to load html template in to grapesjs.I am having separate css folder in my local react app...
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...
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.