Issue #2416πŸ’¬ AnsweredOpened November 15, 2019by ayodele22422 reactions

Unable to display template from database to grapesjs

Quick answerby ayodele2242❀ 1

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

ayodele2242β€’ November 15, 2019

@pouyamiralayi Yes. Please check my updated question.

pouyamiralayiβ€’ November 16, 2019

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

pouyamiralayiβ€’ November 15, 2019

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

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins β†’
Premium option

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.