Issue #2504💬 AnsweredOpened January 12, 2020by andrewryan19060 reactions

How to extend the image asset type to add custom attributes?

Quick answerby artf

Put it in a plugin if you need to update also the already defined assets

Read full answer below ↓

Question

Hello, I'm trying to make a simple modification to the default image asset and am running into a wall, and am sure I'm missing something simple. I need the image element to have an additional attribute that I pass into it, called mySpecialId. I can't figure out how to get the asset to render this into the DOM. I think I'm supposed to extend the image type like this, and I think I should be using the updateTarget method like this: But it's not working. When I click on the image, nothing happens. I think that's because I'm replacing the base updateTarget logic in the image, whereas I want to ex...

Answers (1)

artfJanuary 12, 2020
editor.AssetManager.addType('image', {
	view: {
		attributes: { 'custom-attr': 'custom-value' }
	}
});

Put it in a plugin if you need to update also the already defined assets

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.