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 2800 posts 8791 karma points MVP 8x admin c-trib
    Jun 26, 2020 @ 22:22
    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 487 posts 2996 karma points MVP 8x admin c-trib
    Jun 27, 2020 @ 09:58
    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 4026 posts 15837 karma points MVP 13x admin c-trib
    Jun 27, 2020 @ 11:44
    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 2800 posts 8791 karma points MVP 8x admin c-trib
    Jun 27, 2020 @ 12:08
    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

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Nov 15, 2021 @ 11:30
    Lee Kelleher
    0
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies