grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Template loaded via remote storage is not displayed in the editor

Open jamejillagit opened this issue 6 years ago • 2 comments

Hi,

I am trying to load a default template from remote storage into the editor but nothing is displayed.

As part of of the initialization I have this code:

storageManager: { type: "remote",
autosave: true, autoload: true, stepsBeforeSave: 3, urlStore: "https://myendpoint/lib/remote_storage_load_template.php", urlLoad: "https://myendpoint/lib/remote_storage_load_template.php", params: {}, contentTypeJson: true, },

This is the PHP code from my urlLoad:

header('Content-Type: application/json');

$html = '

Hello world
'; $css = '*{color:red;} body{width:100%;}'; $arr = array( 'gjs-html' => $html, 'gjs-css' => $css, 'gjs-assets' => [], 'gjs-styles' => [], 'gjs-components' => []);

//echo htmlentities(json_encode($arr)); echo json_encode($arr);

This is the JSON that grapesjs loads from my endpoint:

editor.on('storage:load', obj => console.log('Loaded ', obj));

image

When I make a GET request to my endpoint directly, this is what I get: {"gjs-html":"<div class = \"hero\">Hello world<\/div>","gjs-css":"*{color:red;} body{width:100%;}","gjs-assets":[],"gjs-styles":[],"gjs-components":[]}

Am I missing something obvious?

Thanks for your help

jamejillagit avatar Aug 19 '20 14:08 jamejillagit

Hi @jamejillagit !

According to how DOM Components are loaded, it seems like GrapesJS will prioritize loading from the gjs-components property over the gjs-html one as long as it is defined & valid (array, object or JSON string).

If you explicitly want to load from gjs-html, I think your endpoint should not return a valid value for the gjs-components property.

Cheers !

mcottret avatar Aug 24 '20 09:08 mcottret

@jamejillagit be sure to have read this https://grapesjs.com/docs/modules/Storage.html If you're loading back the HTML to update the template, you'll face issues

artf avatar Aug 27 '20 23:08 artf