Issue #2416Opened November 15, 2019by ayodele22422 reactions

Unable to display template from database to grapesjs

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)

ayodele2242November 15, 20191 reactions

@pouyamiralayi Yes. Please check my updated question.

pouyamiralayiNovember 16, 20191 reactions

@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.

pouyamiralayiNovember 15, 20190 reactions

@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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.