[Question] Blockmanager and Image
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)
@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:
blockManager.add("image", {
label: 'Image',
category: 'Basic',
attributes: { class: "gjs-fonts gjs-f-image" },
content: {
style: { color: "black" },
type: "image",
classes: ['class1', 'class2']
activeOnRender: 1,
},
});
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 into canvas asset manager doesn't open. Otherwise if I use image type attribute, it ignore my html content, I saved an example in js fiddle:
https://jsfiddle.net/fp78yon0/
Thanks!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.
Issue #493
[QUESTION] Can i set content dynamically from block API ?
Hi @artf , very great web builder framework and keep it up :+1: code : As you can see, can i make tag dynamically from my backend? i use EJ...
Issue #1034
insert element or block inside parent element
Good day, i have component, have block i have Trait on listen changes, how can I add "h1 " inside that block "'<div class="container" style...
Issue #1134
Add custom style in the style-sheet for a new class of existing block.
Hello @artf _("map") && i.add("map", { label: n.labelMap, category: n.category, attributes: { class: "fa fa-map-o" }, content: { type: "map...
Issue #1220
[Question] Manipulate elements into a selected block in command
How can I manipulate elements into a block content? For example: My block: My component: Command:
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.