Skip to content

Instantly share code, notes, and snippets.

@leekelleher
Created April 5, 2018 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leekelleher/fef3dd7d6a934b8333e270bd5a6aa7ef to your computer and use it in GitHub Desktop.
Save leekelleher/fef3dd7d6a934b8333e270bd5a6aa7ef to your computer and use it in GitHub Desktop.
Umbraco - Overrides the default MacroContainerValueConverter, to return the correct type, HtmlString
using System;
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors.ValueConverters;
using Umbraco.Web.PropertyEditors.ValueConverters;
namespace Our.Umbraco.Web.HotFixes
{
public class MyApplicationEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
PropertyValueConvertersResolver.Current.RemoveType<MacroContainerValueConverter>();
}
}
public class MyMacroContainerValueConverter : MacroContainerValueConverter
{
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
{
var value = base.ConvertDataToSource(propertyType, source, preview);
return value != null ? new HtmlString(value.ToString()) : source;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment