Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • jake williamson 207 posts 872 karma points
    Feb 03, 2015 @ 12:00
    jake williamson
    0

    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?

    [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 ;)

    cheers,

    jake

  • James Jackson-South 489 posts 1747 karma points c-trib
    Feb 11, 2015 @ 17:37
    James Jackson-South
    0

    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

    1. The class
    2. The Converter
    3. How you are calling it in your controller or wherever.
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Feb 11, 2015 @ 17:39
    Lee Kelleher
    2

    Hi Jake,

    Sorry for not replying back sooner.

    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 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 custom TypeConverter - I think that would give a lot more flexibility.

    Cheers,
    - Lee

Please Sign in or register to post replies

Write your reply to:

Draft