Closed nojaf closed 10 years ago
Wouldn't you perform this kind of logic in your controller?
I was thinking of modifing the ConvertToModel
private static void GetPropertyValueOnInstance(IPublishedContent content, object objectInstance, PropertyInfo propertyOnTab, UmbracoPropertyAttribute propertyAttribute, string alias = null)
{
if (alias == null) alias = propertyAttribute.Alias;
//sugestion
string umbracoStoredValue = content.GetPropertyValue<string>(alias, true);
if (propertyAttribute.ConverterType != null)
{
TypeConverter converter = (TypeConverter)Activator.CreateInstance(propertyAttribute.ConverterType);
propertyOnTab.SetValue(objectInstance, converter.ConvertFrom(null, CultureInfo.InvariantCulture, umbracoStoredValue));
}
else
{
propertyOnTab.SetValue(objectInstance, umbracoStoredValue);
}
}
Couldn't hurt I think.
This is indeed something you would want to do in the controller and pass along in your custom RenderModel.
Use case:
On my homepage I want to have an background image that is selected by imagepicker. On a child page I can select the image again but if I didn’t fill it in I want to have one of the ancestors page background image.
If I look at the code now it only checks the current IPublishedContent but in some cases I need to have the ancestor IPublishedContent be checked if it is filled in.