Unable to display template from database to grapesjs
@pouyamiralayi Yes. Please check my updated question.
Read full answer below βQuestion
Able to fetch my remote HTML file using load URL and getting status ok, how can I load this fetched HTML AND CSS into editor? currently I'm getting blank screen inside editor.
What I tried so far:
storageManager: {
id: 'gjs-',
type: 'remote',
autosave: false,
autoload: true,
setStepsBeforeSave: 1,
contentTypeJson: true,
storeComponents: true,
storeStyles: true,
storeHtml: true,
storeCss: true,
urlStore: '../inc/page/edit_builder.php?id=<?php //echo $pid; ?>',
urlLoad: '../inc/page/fetch_builder.php?id=<?php //echo $pid; ?>',
json_encode:{
'gjs-components': "",
'gjs-css': [],
'gjs-html': [],
'gjs-style': []
}
},
From the server
$id = $_GET['id'];
$result = mysqli_query($mysqli, "SELECT * FROM mp_pages WHERE page_id='$id'");
$response= array();
while($row = mysqli_fetch_array($result))
{
array_push($response, array(
"gjs-components"=>$row['gjs-component'],
"gjs-css"=>$row['css'],
"gjs-html"=>$row['page_desc'],
"gjs-style"=>$row['gjs-styles'],
));
}
echo json_encode($response);
mysqli_close($mysqli);
How can I pass the JSON into grapesjs to make it render the HTML and CSS?
Answers (3)
@pouyamiralayi Yes. Please check my updated question.
@ayodele2242 i guess the structure of your response is not correct; what you are sending:
[ [gjs-components => [{obj1}, {obj2}, {obj3} ], [gjs-components => [{obj1}, {obj2}, {obj3} ],.... ]
the correct structure is this. please forgive me if i am wrong, i'm not an expert on php. cheers.
@ayodele2242 do you include gjs-components in your response? i can not see that in above code.
also make sure to not fall into db field type mistake.
cheers!
Related Questions and Answers
Continue research with similar issue discussions.
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 #1700
Grapesjs-react
how to load an html file while starting the GrapesJs-react- editor I tried in this way but it is not working, editor.StorageManager.add('lo...
Issue #1255
[QUESTION]: How to set editor html contents from custom component?
I'm having trouble getting a custom block+component to display its template HTML inside the grapes editor. Within the exported HTML, the ma...
Issue #2264
how to load a remote url inside grapes js
this is how i tried to load my gitpage but its not working mounted() { const LandingPage = { html: '', css: null, components: null, style:...
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 βBrowse Plugin Categories
Jump directly to plugin category pages on the marketplace.