Issue #2596Opened February 24, 2020by cristianumali222 reactions

[QUESTION] Add html, css and js to Block Manager

Question

[QUESTION]

Hi! I'm retrieving dynamic html,css and js codes from the database. How can I create Blocks with this? Currently, this is my code,

    editor.BlockManager.add($aBlock['name'], {
        id: $aBlock['name'],
        label: $aBlock['name'],
        category: $aBlock['category'],
        content: $aBlock['html'],
        style: $aBlock['css'],
        script: $aBlock['css'],
      });

But its not working. Please help. Thank you.

Answers (3)

cristianumali22February 25, 20201 reactions

Hi @pouyamiralayi , thus, doing, content: '<div></div><style></style>' will seperate the HTML from CSS in the download code feature of GrapesJS?

Note that in every blocks of code, there is different HTML, CSS and JS. Is the css of, example block_1, will not affect the style of block_2?

pouyamiralayiFebruary 26, 20201 reactions

@cristianumali22 your code looks fine and it is not executed before grapesjs initialization because you are passing the reference and not actually calling it! i suggest using the grapesjs cli because it is doing all the setups for you and providing you with a nice and clean environment. Cheers!

pouyamiralayiFebruary 24, 20200 reactions

@cristianumali22 please consider putting both your html and css inside the content property like this:

content: '<div></div><style></style>'

for including scripts, you must define a new component type and then proceed to component & js 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.