Closed djomen closed 9 years ago
The type of a property depends on the IPropertyValueConverter that has been defined for the property--since it is the converter that will provide the value. If no converter is defined for a property then we don't know its type and assume it's "object".
For the content picker, you don't want an integer actually. What you want is the picked content. So the type of the property should be IPublishedContent. And there should be a proper converter that converts the raw property value into an IPublishedContent.
For various reasons Umbraco does not ship with many converters at the moment. But in your projects, what you want is to add converters. And then the models builder will find them, understand what's the property's type, and create properties with the proper type.
I understand the converters - so you can have model.GetPropertyValue
but how/where would I tell the model builder that RedirectToNode for example needs to use the IPublishedContent converter (if/when i created one)?
For example... On my Pages class which all my site pages inherit from (and its what i use as the ViewModel on my master page) i have a property for the breadcrumb so that I can then just have a breadcrumb partial that gets the model passed from the masterpage.
This is what i have for the property on my Pages partial class:
public virtual IEnumerable<IPublishedContent>
BreadcrumbPath
{
get
{
var umbHelper = new UmbracoHelper(UmbracoContext.Current, this);
return umbHelper.TypedContent(this.Content.Path.Replace("-1", "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
}
}
Is there a better way to code that?
Re. converters: it's the other way round, a converter implements an IsConverter method so it can tell which properties it is a converter for.
As for your breadcrumb property... it is not a real content property... so what you're doing is OK I think.
any example? i can't find any example ? how to get my image url, it returns integer only
@sukhdev22 if I understand correctly, you would like an example of a property converters that returns the image url instead of the integer, right?
exactly @zpqrtbnk It should give me url automatically, not integer should i add a partial class and define extra logic there? or Is there any way Zbu.ModelsBuilder will do it automatically ?
So that we don't have object - on a content picker for example we could set int for the node id.
Or would it be better to just implement the property ourselves and ask the Builder to ignore? I guess if we did it ourselves then we can go the extra mile and spin up a proper type.