Add a custom attribute
Question
Hi everyone,
I am creating new blocks, when I use the following method:
editor.BlockManager.add(blockId, { label: blockLabel, content: {...blockContent, **"customAttribute": "value"**}, attributes: blockAttributes})
I can read the customAttribute using editor.getSelected().get("customAttribute")
How to add this attribute and be able to get it in the same way as above, if the block created has the content in HTML format and not JSON?
Per example: content: <div></div>
Thank you in advance!
Answers (3)
Hi @alimajed93 try it! editor.BlockManager.get("blockId").attributes.content.customAttribute
@alimajed93 I think you're referring to this
<div data-gjs-custom-attribute="value"></div>
so then editor.getSelected().get('custom-attribute')
Be aware that attributes keys in HTML are case insensitive, therefore data-gjs-customAttribute="value" is parsed to customattribute
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #792
Script property using function don't work with blocks
In Components & JS docs there's this example: This works perfectly. But I couldn't use a function instead of a string in script, as is said...
Issue #701
Modifying a component in the editor clears the model content
What I'm trying to achieve: I have special "data-" attributes on some of the components I pull into the editor. When one of these is modifi...
Issue #1574
Question, Block content from file
Hi, this is not really an issue but more a question. I'm currently using custom blocks in my GrapesJS editor. This is how I create them : I...
Issue #1545
[Question] How I Get ID From Block?
Hi, i have my block and I get print in Div id results from my javascript class component... How i get ID from my block ??? editor.BlockMana...
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.