When adding/editing a block to the blockgrid, the sidebar opens with all the blocktypes properties. But I cant find what the alias of the block?
Im creating a custom property editor and need to know which block type im on?
When adding/editing a block to the blockgrid, the sidebar opens with all the blocktypes properties. But I cant find what the alias of the block?
Im creating a custom property editor and need to know which block type im on?
Hello Jesper.
I think I am also trying to find the answer to this (Retrieving the alias of a block in a custom property editor)
I have been trying to look through the different Context’s that are available, but so far I can’t find out what I need to use to get the alias of the block that you’re currently editing.
I am hoping it’ll be slightly easier for us to find, because in previous versions (13), I was having to do this:
"let alias = $scope.$parent.$parent.$parent.$parent.$parent.$parent.$parent.$parent.$parent.$parent.$parent.model.content.contentTypeAlias;"
Will let you know if I find anything.
Thanks,
Rob
Hi Rob. Yes thats the Umbraco 13 way. I’ll update you as soon as we find a solution. I think there’s a way using the block uid to look it up but …
Hello Jesper.
I haven’t tested it properly and I am not too sure of how much of a long term solution it is as I am sure there is (or will be) a better way in the future.. but.
What I am currently doing to get the alias of the Block that you’re editing is the following:
import { UMB_BLOCK_WORKSPACE_CONTEXT } from "@umbraco-cms/backoffice/block";
constructor() {
super();
this.consumeContext(UMB_BLOCK_WORKSPACE_CONTEXT, (instance) => {
this.observe(instance.content.structure.contentTypeAliases, (aliases) => {
// Get the alias, which is the first item returned in this aliases array.
console.log(aliases[0]);
});
});
};
“aliases” will return an array of other aliases, but I believe it’s the first item every time that we’d be interested in.
Note - I am using the latest version, 16. 0.0.
Hi Robert,
I’ll try this out. Sure seems complicatied
best
jesper