Getting Ancestor of Not yet saved new page
# help-with-umbraco
c
Hey all, Working on a custom property in a Block List. One of my properties (which is using Contentment) gets its values from the 'Current Root Node' which means that a brand new page that has yet to even be saved, doesnt know how to populate this property. Does anyone know, how would you access the current root node in this scenario?
m
Would the
Umbraco.AssignedContentItem.Parent.Root()
be accessible?
c
Are you using a data source that allows setting an XPath? If so you should be able to use
$site
to get to the desired node.
j
There is an issue with blocklist and Contentment not getting the context in general which looks to be fixed from Umbraco 13.1: https://github.com/leekelleher/umbraco-contentment/issues/306
c
Hey all, Sadly the Umbraco.AssignedContentItem is null at this stage so having to look for other means! Thanks for the link Jemayn, looks like we will need to upgrade to 13.1!
m
Can you read the parentId from the current ulr?
https://localhost:44389/umbraco#/content/content/edit/19192?doctype=standardPage&create=true
that 19192 is the parent id, eg the node I right clicked to choose create... 😦 silly me that can't be read serverside... at least not in .net..
One more thought, if you have an angular controller for your custom property...
Copy code
json
function fn($scope, appState) {   
    appState.getTreeState("selectedNode").id;
 }
should get that parent id from the active node in the content tree... šŸ¤” šŸ¤¦ā€ā™‚ļø or indeed like in the fix mentioned above, injecting the editorstate..
Copy code
json
// get current node (for page context)
  var currentPage = editorState.getCurrent();
  var currentPageId = currentPage ? (currentPage.id > 0 ? currentPage.id : currentPage.parentId) : null || -20;
11 Views