Copied to clipboard

Flag this post as spam?

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


  • karen 186 posts 461 karma points
    Feb 03, 2010 @ 22:55
    karen
    0

    Getting multiple node values in code

    I am using a  repeatable custom content datatype and I want to get those values in my code, not on an xslt page.

    It is picking a bunch of images and then I want to randomly display one of those images as the background.

    I have this:

    Node thisPage = Node.GetCurrent();

    and usually use this to get the value of a property on the page:

    thisPage.GetProperty("heroImage").Value

    However, doing this for the repeatable datatype gives me empty string for the value.

    I am wondering how to get the node for heroImage and do I have to use regular xml operations on it or if there is someway to get those items using the umbraco API.

     

    Thanks

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Feb 04, 2010 @ 14:05
    Lee Kelleher
    1

    Hi Karen,

    (Firstly, on a side-point, you might get a response from the Repeatable Custom Content developer if you posted in his support form)

    I have personally use the Repeatable Custom Content with code-behind (C#) - but the property value should return a String (an XML string, which would need to be loaded into an XmlDocument, or similar?)  Which should have this structure.

    <items>
        <item>
            <data alias="alias1">value 1</data>
            <data alias="alias2">value 2</data>
        </item>
        <item>
            <data alias="alias1">value 3</data>
            <data alias="alias2">value 4</data>
        </item>
    </items>

    If there is no value returned, then there might be something wrong with your set-up?  It's worth checking in your cmsPropertyData database table to see if the node has any values, (might look a bit scary if you don't know databases).  Otherwise check your umbraco.config to see if the value is in there.

    Once you get the XML (String) back, do a couple of SelectNodes/XPath and you should get the value you need.

    Good luck, Lee.

  • 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