Issue #894Opened February 23, 2018by alimajed930 reactions

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)

samuelmattosFebruary 23, 20180 reactions

Hi @alimajed93 try it! editor.BlockManager.get("blockId").attributes.content.customAttribute

artfMarch 1, 20180 reactions

@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

lock[bot]September 18, 20190 reactions

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.

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.