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?
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:
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.
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 :)
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:
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
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.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.
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
Cross linking with the follow-up GitHub discussion (at the time)... https://github.com/leekelleher/umbraco-contentment/discussions/89
Updating now, as Claus asks a similar question... https://our.umbraco.com/packages/backoffice-extensions/contentment/contentment-feedback/107597-get-name-from-datalist
is working on a reply...