Skip to content

Commit 46b1213

Browse files
committed
Updated article
1 parent 293b9c7 commit 46b1213

File tree

1 file changed

+64
-17
lines changed

1 file changed

+64
-17
lines changed
Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,80 @@
11
# UDI Identifiers
22

3-
## Introduction
3+
Umbraco uses Unique Document Identifiers (UDIs) to reference most object types, such as content, media, and members. A UDI contains all the metadata needed to retrieve an Umbraco object and is readable within text.
44

5-
Umbraco stores identifiers in UDI format for most Umbraco object types. This identifier stores all of the metadata required to retrieve an Umbraco object and is parse-able within text. Example: `umb://document/4fed18d8c5e34d5e88cfff3a5b457bf2`. UDI's can be used in many of the querying APIs.
5+
Example:
66

7-
{% hint style="info" %}
8-
UDI is currently not an acronym for something. There is no official definition of what it's short for. Therefore it's called *UDI*
9-
{% endhint %}
7+
```text
8+
umb://document/4fed18d8c5e34d5e88cfff3a5b457bf2.
9+
```
1010

11-
## Format
11+
UDIs are commonly used in Umbraco’s querying and management APIs.
1212

13-
An Umbraco UDI consists of three parts: the scheme, the type and a GUID Identifier. For example: `umb://document/4fed18d8c5e34d5e88cfff3a5b457bf2`.
13+
## Format
1414

15-
Breaking it down:
15+
A UDI consists of three parts:
1616

17-
1. The scheme is `umb://` - this is always the same and makes it identifiable as an Umbraco UDI
18-
2. The type is `document` - so in this is an Umbraco node, but it could also be `media`, `member`, etc.
19-
3. The GUID Id is `4fed18d8c5e34d5e88cfff3a5b457bf2` - this is a GUID (dashes removed) which is randomly generated when the item is being created
17+
1. Scheme: `umb://` – Identifies as an Umbraco UDI.
18+
2. Type: `document`– Specifies the object type (for example, media, member, Data Type, and so on).
19+
3. GUID Identifier: `4fed18d8c5e34d5e88cfff3a5b457bf2` – A unique identifier for the object (a GUID without dashes).
2020

2121
## Usage
2222

23-
You can use UDIs in some of the Querying and Management/Service APIs.
23+
UDIs are useful for retrieving content, media, or other Umbraco objects through the API. Below are examples of how to use a UDI in C# to get content or media.
24+
25+
### Retrieving Content by UDI
26+
27+
You can retrieve a content item using `IContentService`:
28+
29+
```cs
30+
using Umbraco.Cms.Core.Services;
31+
using Umbraco.Cms.Core.Models
32+
33+
@inject IContentService contentService
34+
35+
@{
36+
// Define the UDI string here
37+
var udiString = "umb://document/334cadfa62dd49049aad86b6e4c02aac"; // Example UDI string
38+
39+
if (udiString.StartsWith("umb://document/"))
40+
{
41+
// Extract the GUID from the UDI string
42+
var guidString = udiString.Replace("umb://document/", "");
43+
if (Guid.TryParse(guidString, out var guid))
44+
{
45+
// Retrieve the content by GUID
46+
var content = contentService.GetById(guid);
47+
if (content != null)
48+
{
49+
// Access the body text field
50+
var bodyText = content.GetValue<string>("bodyText"); // Replace 'bodyText' with the alias of your body text field
51+
<p>@bodyText</p> // Output the body text
52+
}
53+
else
54+
{
55+
<p>Content not found.</p>
56+
}
57+
}
58+
else
59+
{
60+
<p>Invalid GUID in the UDI string.</p>
61+
}
62+
}
63+
}
64+
```
65+
66+
## UDI Types
67+
68+
There are two types of UDIs in Umbraco:
69+
70+
### GUID UDI
2471

25-
There are 2 types of UDIs:
72+
Used for objects that have a GUID identifier, such as content and media.
2673

27-
## GUID UDI
74+
* [API Reference: GuidUdi](https://apidocs.umbraco.com/v15/csharp/api/Umbraco.Cms.Core.GuidUdi.html)
2875

29-
* [API Reference](https://apidocs.umbraco.com/v15/csharp/api/Umbraco.Cms.Core.GuidUdi.html)
76+
### String UDI
3077

31-
## String UDI
78+
Used for objects that are not GUID-based, such as dictionary items.
3279

33-
* [API Reference](https://apidocs.umbraco.com/v15/csharp/api/Umbraco.Cms.Core.StringUdi.html)
80+
* [API Reference: StringUdi](https://apidocs.umbraco.com/v15/csharp/api/Umbraco.Cms.Core.StringUdi.html)

0 commit comments

Comments
 (0)