Custom value conversion for rendering
Add a Property Value Converter for custom Property Editor value conversion.
Overview
In the previous steps, we created a custom Property Editor for the Umbraco backoffice client. In this step, we will discuss how to convert the Property Editor values for use when rendering the website.
To this end, we will create a Property Value Converter that converts the stored suggestion text into a custom rendering model.
When should I use a Property Value Converter?
A Property Value Converter is usually not necessary. Based on the chosen propertyEditorSchemaAlias
, Umbraco will automatically provide appropriately typed models for rendering the Property Editor. For more information, see the Default Property Editor Schema Alias options article.
The most common use-cases for building a Property Value Converter are:
Property Editors that store values which require server-side conversion, in order to render an appropriate output.
Property Editors with specific caching requirements.
Tailoring the Property Editor output value specifically for the Content Delivery API.
Implementing a Property Value Converter
A Property Value Converter must meet a few required responsibilities:
Identifying itself as being able to convert values for a given Property Editor.
Declaring the concrete runtime type it will be outputting.
Performing the value conversion from the stored
The following code snippet outlines how these could be solved for our suggestion
Property Editor.
We have used the property type editor UI alias from umbraco-package.json
in the implementation of IsConverter()
.
For more advanced Property Value Converter techniques (for example, controlling caching), see the Property Value Converters article.
Last updated