# Resolve dynamic links

## Overview

Sitefinity CMS enables you to automatically update the references you make from your content item to other content - media or pages - thus avoiding the need to update links manually every time referenced content is modified. As a result, there are no outdated content references and broken links.

For example, if your content item links to an image, Sitefinity CMS automatically resolves every reference to this image even after modifications such as changes in title, address, or even replacement with another image are done.

To correctly retrieve and persist content from and to the database, Sitefinity CMS includes an `sfref` attribute to the `HTML` tag of the referenced content. The `sfref` attribute holds important information - the `Guid` of content item you are referencing to and, depending on the type of content item, the following:

 <table>
<colgroup><col><col></colgroup>
<tbody>
<tr>
<td>

<strong>Content type</strong>

</td>
<td>

<strong>sfref attribute</strong>

</td>
</tr>
<tr>
<td>

Images

</td>
<td>

<code>\[images|providername]image_id</code>

</td>
</tr>
<tr>
<td>

Documents

</td>
<td>

<code>\[documents|providername]document_id</code>

</td>
</tr>
<tr>
<td>

Videos

</td>
<td>

<code>\[videos|providername]video_id</code>

</td>
</tr>
<tr>
<td>

Pages

</td>
<td>

<code>\[rootNodeId]page_id</code>

</td>
</tr>
</tbody>
</table>

When you create a content item that links to other content or pages, this content item is persisted to the database. As a result, Sitefinity CMS injects the value of the `sfref` attribute as a value of the `src` attribute of the `HTML` tag of the content that you saved to the database. Upon retrieval from the database, Sitefinity CMS resolves this content item using a link parser. The `DynamicLinkParser` class in Sitefinity CMS is a `Helper` class for resolving and unresolving dynamic links in HTML formatted text. Depending on where you view the item from, the `sfref` attribute is resolved differently:

* Backend:\
  Both the `src` and `sfref` attributes hold their respective values. The `sfref` in the backend is used by Sitefinity's designer dialogs. When you open an image in the backend using a designer, the `sfref` attribute locates the correct content item to be opened in the designer mode.
* Frontend:\
  The `sfref` attribute is omitted, so that it does not inflate the HTML with unnecessary information.

## Resolve dynamic links programmatically

### Resolving links using the .NET Framework API

If you choose to implement your own logic for displaying HTML content of content items, you must resolve all links to other content - media or pages. To do so refer to the following example:

```C#
using System;
using System.Linq;
using Telerik.Sitefinity.Modules.GenericContent;
using Telerik.Sitefinity.Modules.News;
using Telerik.Sitefinity.News.Model;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules
{
    public partial class DynamicLinksSnippets
    {
        public static string GetResolvedNewsItemHtml(Guid newsItemMasterId, bool preserveOriginalValue, bool resolveAsAbsoluteUrl)
        {
            // Get an instance of the news manager and find the news item
            NewsManager manager = NewsManager.GetManager();
            NewsItem newsItem = manager.GetNewsItems().FirstOrDefault(x => x.Id == newsItemMasterId);

            string resolvedContent = String.Empty;

            if (newsItem != null)
            {
                // Resolve the html content to get the actual URL paths 
                DynamicLinksParser dynamicLinksParser = new DynamicLinksParser(preserveOriginalValue, resolveAsAbsoluteUrl);
                resolvedContent = dynamicLinksParser.Apply(newsItem.Content);
            }

            return resolvedContent;
        }
    }
}

```

In the code above, you get an instance of the `DynamicLinksParser` class and call the `Apply` method. As a result all dynamic links in the specified HTML text are resolve to point to their actual location. When creating the `DynamicLinksParser` class instance, you can pass constructor parameters to remove the `sfref` attribute from the HTML and resolve URL's with their absolute path.

### Resolving links in decoupled renderers

To resolve dynamic links automatically in a widget based on a decoupled renderer technology, decorate the widget's properties with the `DynamicLinksContainer` attribute.

ASP.NET example:

```C#
[DynamicLinksContainer]
public string Content { get; set; }
```

Next.js example:

```JavaScript
@DynamicLinksContainer()
public Content: string;
```
