Question : Layer labels
Question
@artf I am loving working with GJS. I have one last thing I'd love your help on.
It would be incredibly helpful to be able to customise the labels in the layer manager. I've searched high and low but not found anything.
The default way it just shows Text and Box is not very helpful when wanting to navigate efficiently.
I would really like to be able to customise these myself. In my case, I'd like to show the tagname and the id.
Many thanks
Answers (3)
You can extend the model of your component/s and overwrite the getName function
In case this is useful for anyone, I found an easy/alternative way of doing this when a component is created.
editor.on('component:create', function(component) {
// filter the tag types you're interested in
if( component.attributes.tagName === 'div' ) {
// Get some information you want to use as the replacement text
// In my case, the component element's id attribute, which is stored in component.ccid
const idParts = component.ccid.split('-')
if( idParts.length > 0 && idParts[0] === 'cbt') {
// This is specific to my case, but 'component.attributes.name' is the field that appears in the layer manager
component.attributes.name = ''
for( let i=1; i < idParts.length; i++ ) {
component.attributes.name += idParts[i].charAt(0).toUpperCase() + idParts[i].slice(1) + ' '
}
}
else {
component.attributes.name = 'Div'
}
}
})
This is how I did it:
grapesInstance.on('component:create', (component) => {
component.getName = () => component.attributes['custom-name'] || `${component.attributes.tagName}#${component.ccid}`;
});
The benefit is that if the components id or tag change later it will still be updated in the layer manager and you can also rename individual components.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1659
[Question] How to upload PDF and others files - GrapesJS
Hi @artf, I started using your web builder a few days ago and I found it very well done ! I was able to customize it in my own way but I ha...
Issue #3269
Translating html string
Great library! It meets all the requirements but one: website text translation. I've searched high and low through the issue queue and docs...
Issue #1822
[QUESTION] - Add style sector for specific Css rule
Hey @artf , COuld you give your help on this one? I want to disable the user to able to select the wrapper block (body) but I still want to...
Issue #543
Blocks Manager in GrapesJS Not Working For Columns
Hello, My installation of GJS ties in all of the default blocks. Every block drags fine onto the page with the exception of all the "column...
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.