Property Value Converters
A guide to creating a custom property value converter in Umbraco
A Property Value Converter converts a property editor's database-stored value to another type. The converted value can be accessed from MVC Razor or any other Published Content API.
For example the standard Umbraco Core "Content Picker" stores a nodeId as
Stringtype. However if you implement a converter it could return an
Published property values have four "Values":
- Source - The raw data stored in the database, this is generally a
- Intermediate - An object of a type that is appropriate to the property, e.g. a nodeId should be an
Intor a collection of nodeIds would be an integer array,
- Object - The object to be used when accessing the property using a Published Content API, e.g. UmbracoHelper's
- XPath - The object to be used when the property is accessed by XPath; This should generally be a
PropertyValueConverters are automatically registered when implementing the interface. Any given PropertyEditor can only utilize a single PropertyValueConverter.
If you are implementing a PropertyValueConverter for a PropertyEditor that doesn't already have one, creating the PropertyValueConverter will automatically enable it and no further actions are needed.
If you are attempting to override an existing PropertyValueConverter (this could be one included with Umbraco or in a package), you will however need to take some additional steps to deregister the existing one to avoid conflicts:
public class MyComposer : IComposer
public void Compose(IUmbracoBuilder builder)
//If the type is accessible (not internal) you can deregister it by the type:
//If the type is not accessible you will need to locate the instance and then remove it:
var contentPickerValueConverter = builder.PropertyValueConverters().GetTypes().FirstOrDefault(x => x.Name == "ContentPickerValueConverter");
if (contentPickerValueConverter != null)
The built-in PropertyValueConverters included with Umbraco, are currently marked as internal. This means you will not be able to remove them by type since the type isn't accessible outside of the namespace. In order to remove such PropertyValueConverters, you will need to look up the instance by name and then deregister it by the instance. This could be the case for other PropertyValueConverters included by packages as well, depending on the implementation details.
Umbraco.Cms.Core.PropertyEditorsnamespace on your class
public class ContentPickerValueConverter : IPropertyValueConverter
This method is called for each PublishedPropertyType (Document Type Property) at application startup. By returning
Trueyour value converter will be registered for that property type and your conversion methods will be executed whenever that value is requested.
Example: Checking if the IPublishedPropertyType EditorAlias property is equal to the alias of the core content editor. This check is a string comparison but we recommend creating a constant for it to avoid spelling errors:
public bool IsConverter(IPublishedPropertyType propertyType)
This method is called to determine if the passed-in value is a value, and is of the level specified. There's a basic implementation of this in
This is where you can specify the type returned by this Converter. This type will be used by ModelsBuilder to return data from properties using this Converter in the proper type.
Example: Content Picker data is being converted to
public Type GetPropertyValueType(IPublishedPropertyType propertyType)
Here you specify which level the property value is cached at.
A property value can be cached at the following levels:
Do not use this cache level unless you know exactly what you're doing. We recommend using the
The property value will be cached until its element is modified. The element is what holds (or owns) the property. For example:
- For properties used at the page level, the element is the entire page.
- For properties contained within Block List items, the element is the individual Block List item.
This is the most commonly used cache level and should be your default, unless you have specific reasons to do otherwise.
The property value will be cached until any element (see above) is changed. This means that any change to any page will clear the property value cache.
This is particularly useful for property values that contain references to other content or elements. For example, the Content Picker uses this cache level to ensure that the Content Picker property values are cleared from the cache whenever the content is updated.
The property value will only be cached for the duration of the current snapshot.
A snapshot represents a point in time. For example, a snapshot is created for every content request from the frontend. Any property accessed within a snapshot using this cache level will be converted and cached for the duration of the snapshot, and then cleared from the cache again.
For all intents and purposes, think of this cache level as "per request". If your property value should only be cached per request, this is the cache level you should use. Use it with caution, as the added property conversions incur a performance penalty.
The property value will never be cached. Every time a property value is accessed (even within the same snapshot) property conversion is performed explicitly.
Use this cache level with extreme caution, as it incurs a massive performance penalty.
public PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
There are a few different levels of conversion which can occur.
This method should convert the raw data value into an appropriate type. For example, a node identifier stored as a
Stringshould be converted to an
using Umbraco.Extensions;to be able to use the
public object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
if (source == null) return null;
var attemptConvertInt = source.TryConvertTo<int>();
var attemptConvertUdi = source.TryConvertTo<Udi>();
This method converts the Intermediate to an Object. The returned value is used by the
The below example converts the nodeId (converted to
Udiby ConvertSourceToIntermediate) into an 'IPublishedContent' object.
public object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
if (inter == null)
if ((propertyType.Alias != null && PropertiesToExclude.Contains(propertyType.Alias.ToLower(CultureInfo.InvariantCulture))) == false)
if (inter is int id)
content = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(id);
if (content != null)
var udi = inter as GuidUdi;
if (udi == null)
content = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(udi.Guid);
if (content != null && content.ContentType.ItemType == PublishedItemType.Content)
This method converts the Intermediate to XPath. The return value should generally be of type
In the example below, we convert the nodeId (converted by ConvertSourceToIntermediate) back into a
public object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
if (inter == null) return null;