Issue #2596💬 AnsweredOpened February 24, 2020by cristianumali222 reactions

Add html, css and js to Block Manager

Quick answerby cristianumali221

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 block1, will not affect the style of block2?

Read full answer below ↓

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

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

@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, 2020

@cristianumali22 please consider putting both your `html and css inside the content` property like this: 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...

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.