In this tutorial, you will learn how to get the published content from a UID in Umbraco V7. When working with document types and properties within Umbraco, 99% of the time you will be dealing with IPublishedContent
and referencing them using its ID
property. If you use the Umbraco Model Builder and you work with properties like the content picker, the multi-node tree picker, nested content, related link media, or third-party packages like Vorto, you may sometimes bump into Umbraco Uid. A Umbraco Uid will look something like this:
If you want to convert the Umbraco UID in code, you can use the Udi class, like so:
You can also use a slightly more dangerous approach:
I advise against this approach, if the UDI is in the wrong format Parse()
will throw an exception, which can lead to odd bugs in your application.
You could also pass the UDI into the UmbracoHelper
as a string, like this:
Or with a UDI entity like this:
As you can see, there are a number of ways to get an IPublishedContent
from a Uid. Happy Coding 🤘