if you're using v4.7, you'll have to parse the xml returned from your property and use linq 2 xml to fetch the required data for a specific culture. 4.7.1 should have support for syntax similar to this example posted by Sebastiaan.
I came up with this solution if anybody else needs it:
XElement xmlParser = XElement.Parse(productMedia.getProperty("additionalNaming").Value.ToString()); IEnumerable query = from array in xmlParser.Elements("value") select array; string cultureName = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
foreach (XElement rep in query) { if (cultureName == rep.FirstAttribute.Value.ToString()) { //Found current culture and matching attribute culture... } }
Thanks for helping me in the right direction, Dirk!
The problem with this, for me, was that if the dictionary fields are not filled in this brings problems. (I'm using Umbraco 4.7.1.1) Your value is something like this then: <value xml:lang="nl-BE" id="2" /> so, not quite usefull.
I used this dictionary datatype to give my images a culture-related caption (for in alt message or image caption in galleries) After working with the ImageXML I wrote a quite usefull helper. It returns the correct dictionary item if it's filled in, otherwise it returns the node name of the Image.
Dictionary Datatype and Razor
Does anybody have an example of how to use the Dictionary Datatype in Razor?
I'm using the datatype on a Media Item and I can get a copy of the xml with:
But how do I filter on the current culture?
Razor is still pretty new to me, so might be an easy one... :)
Thanks in advance!
Ohhh...
Response.Write(productMedia.getProperty("additionalNaming").Value.ToString());
Outputs:
<arrayofvalue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<value xml:lang="en-US" id="1">en</value>
<value xml:lang="da-DK" id="2">da</value>
<value xml:lang="de-DE" id="3">de</value>
</arrayofvalue>
if you're using v4.7, you'll have to parse the xml returned from your property and use linq 2 xml to fetch the required data for a specific culture. 4.7.1 should have support for syntax similar to this example posted by Sebastiaan.
https://gist.github.com/1170848
Cheers,
/Dirk
I am using 4.7.0, will give it a shot. Hoped for an easy solution. :)
I came up with this solution if anybody else needs it:
XElement xmlParser = XElement.Parse(productMedia.getProperty("additionalNaming").Value.ToString());
IEnumerable query = from array in xmlParser.Elements("value") select array;
string cultureName = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
foreach (XElement rep in query)
{
if (cultureName == rep.FirstAttribute.Value.ToString())
{
//Found current culture and matching attribute culture...
}
}
Thanks for helping me in the right direction, Dirk!
The problem with this, for me, was that if the dictionary fields are not filled in this brings problems. (I'm using Umbraco 4.7.1.1)
Your value is something like this then: <value xml:lang="nl-BE" id="2" /> so, not quite usefull.
I used this dictionary datatype to give my images a culture-related caption (for in alt message or image caption in galleries)
After working with the ImageXML I wrote a quite usefull helper. It returns the correct dictionary item if it's filled in, otherwise it returns the node name of the Image.
is working on a reply...