What is the best way to get the content key of a n...
# package-development
w
What is the best way to get the content node ID/Key ?
Using umb-debug there seems to be lots of different contexts with unique properties or getUnique methods. So is there a best/preferred one to use or is it just take a pick at whatever you want?!
* UmbEntityContext.unique * UmbEntityContext.getUnique() * UmbWorkspaceContext.unique * UmbWorkspaceContext.getUnique() * UmbPropertyDatasetContext.unqiue (Not on this ctx) * UmbPropertyDatasetContext.getUnique()
j
Looks like you are inside a property editor, so probably UmbPropertyDatasetContext in this case.
If your component needs to work more broadly than that, then UmbWorkspaceContext is a good bet
w
I am in a WorkspaceView
Went with
UMB_DOCUMENT_WORKSPACE_CONTEXT
in the end
For anyone who stumbles across this thread on discord or via google with https://discord-chats.umbraco.com/
This was what I used in a
WorkspaceView
Copy code
TS
this.consumeContext(UMB_DOCUMENT_WORKSPACE_CONTEXT, (docWorkspaceCtx) => {
  // Used get rather than observing the content key/guid as its not going to change whilst I am on the page AFAIK
  this._unique = docWorkspaceCtx.getUnique();
  console.log('Content Key', this._unique);
});
j
Oh yeah, that also gets the PropertyDatasetContext
5 Views