public static IPublishedContentWithKey GetContentWithKey(IPublishedContent model)
{
var withKey = model as IPublishedContentWithKey;
if (withKey != null) return withKey;
var wrapped = model as PublishedContentWrapped;
if (wrapped != null)
{
return GetContentWithKey(wrapped.Unwrap());
}
return null;
}
public static Guid GetContentKey(this IMasterModel model)
{
var withKey = GetContentWithKey(model);
if (withKey != null) return withKey.Key;
return Guid.Empty;
}
in the file 'umbracoSettings.config' under the folder 'Config'
Now it's two days that I stuck. I think I will give up and downgrade Umbraco to a previous version where the old editors were in use.
The reason why i wanted to to do this is because I am working with
the Umbraco Rest API, that only accepts ids to retrieve the content and does not accept routes or udi.
The Property value converters are controlled by an umbracoSetting.config setting: in section settings/content, setting EnablePropertyValueConverters set to false.
And you will be able to use old school ids in your properties.
I changed the key to false in the umbracoSettings.config, cleared the plugin cache and all the other cache folders, stopped evey instance of iis express in memory and restarted umbraco, but the content picker never changed.
I wonder why the mapped queries in the CMS and IPublishedContent do not store to the property key. The key is present both in the database and in the file umbraco.config under App_Data/Temp and it's used to generate the udi.
I had a look at the class UDI in the Umbraco Core and it does not seem to have a method to reverse the Udi
Here is a JavaScript function that I wrote to match and replace udi.
The input is the html string to parse and the sitelinks is a list of the Umbraco pages.
function filterByUdi() {
return function(input, siteLinks) {
if (input) {
var regex2 = /href=\"\/{localLink:umb:\/\/document([^\"]*)"/g;
var links = input.match(regex2);
if (links && siteLinks) {
var output = input.replace(/data-udi=\"([^\"]*)\"/g, "");
for (var j = 0; j < siteLinks.length; j++) {
for (var k = 0; k < links.length; k++) {
if (links[k].includes(siteLinks[j].NodeUdi)) {
if (siteLinks[j].Url === "/") {
output = output.replace(links[k], 'href=\"#!home\"');
} else {
output = output.replace(links[k], 'href=\"#!' + siteLinks[j].Url + '\"');
}
}
}
}
return output;
}
}
return input;
};
}
From UDI to ID
Hi everyone,
is it possible get the document id or document id from the new property udi? What is the relation between id and udi?
IpublishedContent does not contain the property 'key' (GUID) that is present in /App_Data/umbraco.config. Is there a way for getting it?
Thanks in advance
Enrico
Hi Enrico,
The easiest way is to use UmbracoHelper like that:
Thanks,
Alex
Thanks Alex, for your help.
I was trying to do also the other way around. Any ideas?
my code was
What other ways for example?
Hi Alex,
thanks for getting back to me.
As you can see from the code, in my API controller I just want to return an object containing the the Udi
Enrico, where in this code do you need udi to id?
Hi Alex,
I need to create a list of all the pages in the websites containing at least the Guid property called 'key'. It would be great to have the UDI.
Then I select the homepage
Then I add the data of the homepage to the list
Is it empty?
this is always empty.
I tried also to implement IPublishedContentWithKey, but the key is always empty.
I checked also the file Umbraco.config in the folder App_Data and the key are ok for every content.
This all the code from my controller
Enrico, did you try this method - https://github.com/Shazwazza/Articulate/blob/master/src/Articulate/Models/PublishedContentExtensions.cs#L52?
I tried also this approach.
I also tried to restore the obselete editors adding the key
in the file 'umbracoSettings.config' under the folder 'Config'
Now it's two days that I stuck. I think I will give up and downgrade Umbraco to a previous version where the old editors were in use.
The reason why i wanted to to do this is because I am working with the Umbraco Rest API, that only accepts ids to retrieve the content and does not accept routes or udi.
Enrico, try to disable PropertyValueConverters.
The Property value converters are controlled by an umbracoSetting.config setting: in section settings/content, setting EnablePropertyValueConverters set to false.
And you will be able to use old school ids in your properties.
will not help you
Thanks for your kind help.
But also this setting doesn't work.
I will try tomorrow with an older version of Umbraco. Hopefully the code I already wrote, will work.
what is the problem if you disable PropertyValueConverters?
Hi Alex,
thanks for getting back to me.
I changed the key to false in the umbracoSettings.config, cleared the plugin cache and all the other cache folders, stopped evey instance of iis express in memory and restarted umbraco, but the content picker never changed.
I wonder why the mapped queries in the CMS and IPublishedContent do not store to the property key. The key is present both in the database and in the file umbraco.config under App_Data/Temp and it's used to generate the udi.
I had a look at the class UDI in the Umbraco Core and it does not seem to have a method to reverse the Udi
To get the key the only way was to use this code:
Now I can manage the Udi property
Thanks Alex for your help
Hi Enrico
You are welcome, glad that you found a solution. ApplicationContext.Services.ContentService.GetRootContent().First() will call database, but it works.
Thanks,
Alex
Hi Alex,
is Examine the best way to query the cahe?
Sorry for the necropost but I stumbled upon this page while searching for a way to get the node udi from the node id.
In the end I solved the problem with this code (which should not hit the database), maybe it can help someone else:
Hi Enrico
Yes, Examine is the fastest way to query data from Examine index, it's not the same as cache little bit. But it's the fastest way to query data.
Did you read this article: https://our.umbraco.org/documentation/reference/Common-Pitfalls/
Thanks,
Alex
Here is a JavaScript function that I wrote to match and replace udi. The input is the html string to parse and the sitelinks is a list of the Umbraco pages.
I hope it could be helpful
Thanks @Enrico for the solution.
After the Umbraco 8 Code clean up the accessing methods got changed compared to Umbraco 7
So, I have updated the code for Get UID from ID in Umbraco 8 as follows
is working on a reply...