Issue #1471✓ SolvedOpened October 1, 2018by alfaalex812 reactions

Blockmanager and Image

Quick answerby arthuralmeidap2

@alfaalex81 For the content object, you can add a new index called classes. This index needs to be an array of classes, which will be applied to the new Image block; Final code:

Read full answer below ↓

Question

Hi! I use this code to add a new block:

    blockManager.add("image", {
        label: 'Image',
        category: 'Basic',
        attributes: { class: "gjs-fonts gjs-f-image" },
        content: {
            style: { color: "black" },
            type: "image",
            activeOnRender: 1,
        },
    });

How can add a custom class to the img tag when i drop into canvas?

Thanks.

Answers (3)

👍 Most helpfularthuralmeidapOctober 1, 2018

@alfaalex81 For the content object, you can add a new index called classes. This index needs to be an array of classes, which will be applied to the new Image block; Final code:

alfaalex81October 2, 2018

Awesome! I have another question for the same argument. I need to create a custom block with an image inside, for example: <div> <ul> <li> <div><a href="#link"><img src="" alt="Title Image" /></a></div> <a href="#link" >Title</a> </li> </ul> </div> I add the code with block manager, but on drop int...

arthuralmeidapOctober 3, 2018

This is not the current grapesjs's behavior. the AssetManager only opens if you dropping directly am img block.

You must have to select the img block within your custom block and execute a code like that:

editor.runCommand('open-assets', {
  target: editor.getSelected()
});

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.