Copied to clipboard

Flag this post as spam?

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


  • Chriztian Steinmeier 2717 posts 8195 karma points MVP 4x admin c-trib
    1 week ago
    Chriztian Steinmeier
    1

    How can I output the label of a DataList item?

    Hi there!

    I've just implemented a Data List picker using an XML file for the data and an Item Picker as the editor.

    The XML is very simple values like this:

    <value id="1234">Label</value>
    

    I am selecting the @id attribute (because it's guaranteed unique) as the key and the content (text()) as the name.

    When I need to output this on the frontend, I need to render the name instead of the key, but the value I get from Models Builder is (probably rightly so) the key.

    I'd love to not have to do my own lookup into the XML file for this - is there a way to get access to the .Name, .Icon etc. properties of the picked item from within my partials?

    /Chriztian

  • Anders Bjerner 434 posts 2446 karma points MVP 4x admin c-trib
    1 week ago
    Anders Bjerner
    101

    Hi Chriztian,

    Are you using your own custom XML data source? Or the one build in to Contentment?

    If you have build a custom data source (via your own C# class), you can have the class implement the IDataListSourceValueConverter interface - there is a bit of documentation here:

    https://github.com/leekelleher/umbraco-contentment/blob/develop/docs/editors/data-list.md#providing-custom-values-for-published-content

    The default XmlDataListSource class does however not implement this interface, so it will return the what you have configured to be the value. From what I can tell, it currently doesn't support getting the entire XML element instead of just the ID.

  • Lee Kelleher 3906 posts 14864 karma points MVP 10x admin c-trib
    1 week ago
    Lee Kelleher
    1

    Good point. It was by design (as in I only needed the value/key for my original use case), but I'll put some thought on how it could be evolved.

  • Chriztian Steinmeier 2717 posts 8195 karma points MVP 4x admin c-trib
    1 week ago
    Chriztian Steinmeier
    0

    Thanks Anders & Lee,

    Yes, I'm using the built-in XML data source - I'll have a look at the IDataListSourceValueConverter to see if it makes sense for me to try (I had seen it but didn't think I'd ever be needing anything out of the ordinary, haha :)

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft