How to extend the image asset type to add custom attributes?
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:
am.addType('image', {
view: {
updateTarget( target) {
..some code here, but what?
}
},
});
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 extend it.
When I try to create my own, second asset type - image2 - nothing renders in the asset explorer. I think that's because the default asset render command only renders assets of type image, but I can't figure out how/where to make it render other kinds of objects when someone drags an Image onto the canvas.
Help greatly appreciated.
Thanks Andrew
Answers (1)
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.
Issue #1044
change src for image element in model
hello when a image block drop to editor i hide the default asset manager and display my custom asset manager: fot this i have no problem.bu...
Issue #2741
How to wrap component with text nodes based on trait?
Hello @artf , I'm not sure if this goes here but I can't figure out from the documentation how to update the component model based on a tra...
Issue #2697
[QUESTION] Problem with custom component type and table cell
Hello! I'm trying to add custom component type: And also I'm adding new block: But when I drop this block on the canvas the <td> tag doesn'...
Issue #634
How can I pass content with script?
I made custom component like this way and used script as well then script is working fine but I am not able to select component. Is there a...
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.