Issue #2963💬 AnsweredOpened August 19, 2020by jamejillagit1 reactions

Template loaded via remote storage is not displayed in the editor

快速解答by mcottret1

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

Read full answer below ↓

Question

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",

代码片段TEXT
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 = '<div class = "hero">Hello world</div>';
$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](https://user-images.githubusercontent.com/64067337/90645170-ecab1300-e235-11ea-92ef-b4314e9ba991.png)

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

Answers (2)

mcottretAugust 24, 2020

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 !

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 →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.