getting to grips with ditto and type converters - working a treat for data type conversion ;)
hadda question though: have you ever had a situation where you need to pass multiple umbraco properties to the converter?
in our example we have the 'name' of the node and a optional property called 'navTitle'. if 'navTitle' has a value, it overrides the 'name' value for navigation.
i could pass the id of the node to the converter, get the IPublishedContent and the 'name' and 'navTitle' property and do the comparison... but that feels like i'm getting the node twice?
i was wondering if it's possible to pass more than property to converter via the 'UmbracoProperty' declaration?
[TypeConverter(typeof(NavTitleConverter))]
[UmbracoProperty("Name","navTitle")]
public string Name{ get; set; }
i guess if you got maybe a list of the values?
just throwing it out - passing the id and getting the content again works but it 'feels' like there's a better way ;)
Could you post a quick example of the code that you are using? I'm struggling to follow the process you are using and this doesn't feel like a scenario I would visit.
E.g
The class
The Converter
How you are calling it in your controller or wherever.
I'm wondering for your example, wouldn't you want to swap around the params?
[UmbracoProperty("navTitle", "Name")]
public string Name { get; set; }
That way if the "navTitle" has a value it will be used, otherwise falling back on the "Name" property.
Failing that you could hook into the convertedTypeFunc delegate - and manipulate the values in there.
I can give a code example if you want?
A potential future feature could be to have an attribute that makes the IPublishedContent node available to the custom TypeConverter - I think that would give a lot more flexibility.
passing multiple properties to a type converter?
hi lee,
getting to grips with ditto and type converters - working a treat for data type conversion ;)
hadda question though: have you ever had a situation where you need to pass multiple umbraco properties to the converter?
in our example we have the 'name' of the node and a optional property called 'navTitle'. if 'navTitle' has a value, it overrides the 'name' value for navigation.
i could pass the id of the node to the converter, get the IPublishedContent and the 'name' and 'navTitle' property and do the comparison... but that feels like i'm getting the node twice?
i was wondering if it's possible to pass more than property to converter via the 'UmbracoProperty' declaration?
i guess if you got maybe a list of the values?
just throwing it out - passing the id and getting the content again works but it 'feels' like there's a better way ;)
cheers,
jake
Could you post a quick example of the code that you are using? I'm struggling to follow the process you are using and this doesn't feel like a scenario I would visit.
E.g
Hi Jake,
Sorry for not replying back sooner.
I'm wondering for your example, wouldn't you want to swap around the params?
That way if the "navTitle" has a value it will be used, otherwise falling back on the "Name" property.
Failing that you could hook into the
convertedType
Func
delegate - and manipulate the values in there.I can give a code example if you want?
A potential future feature could be to have an attribute that makes the
IPublishedContent
node available to the customTypeConverter
- I think that would give a lot more flexibility.Cheers,
- Lee
is working on a reply...