Copied to clipboard

Flag this post as spam?

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


  • Lee 1130 posts 3088 karma points
    Dec 14, 2009 @ 12:53
    Lee
    0

    Can I Read DropDownList DataType Values Using XSLT?

    I have a drop down list dataType that is pre populated allowing users in the admin section to choose from the list - I basically need to show this drop down list in the front end as well for data filtering purposes?  Can I pull through that DDL dataType in XSLT?

    As I'd like it when the values are updated that are auto shown in the front end?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 14, 2009 @ 13:10
    Dirk De Grave
    2

    Lee,

    you can use 

    umbraco.library:GetPrevalues(id)

    (id is the id of the datatype when hovering over the datatype)

    It returns an xml fragment

    <preValues><preValue id="x">value</preValue>...</preValues>

    so you can iterate those using xslt quite easily

    All values are taken from the cmsDataTypeprevalues table sorted on sortorder column

     

    Hope this helps.

    Regards,

    /Dirk

  • Lee 1130 posts 3088 karma points
    Dec 14, 2009 @ 13:29
    Lee
    0

    You're a gentleman - thanks :)

  • Lee 1130 posts 3088 karma points
    Dec 14, 2009 @ 13:46
    Lee
    0

    Actually I just used this and I get back in one big string of all the values?  If I do this

    <xsl:value-of select="umbraco.library:GetPreValues('1102')"/>

    It just gives me

    valueonevaluetwovaluethreevaluefour

    This is what I was trying to do?  Am I missing something?

    <xsl:for-each select="umbraco.library:GetPreValues('1102')/node">    
        <option value="{@id}">
            <xsl:value-of select="@nodeName"/>
        </option>
    </xsl:for-each>

    Thanks

  • Lee 1130 posts 3088 karma points
    Dec 14, 2009 @ 13:50
    Lee
    1

    Sorted it :)

       <xsl:variable name="topicList" select="umbraco.library:GetPreValues('1102')"/>
            <xsl:for-each select="$topicList//preValue">  
                <option value="{@id}">
                    <xsl:value-of select="current()"/>
                </option>
        </xsl:for-each>
  • Sean Dooley 289 posts 528 karma points
    Jun 29, 2011 @ 18:03
    Sean Dooley
    0

    I'm trying to achieve the same thing with Razor - the code below outputs "SmallMediumLarge"

    <select class="item_size">
    @{
      var preValues = umbraco.library.GetPreValues(1081);
      foreach(var pv in preValues)
      {
        <option value="">@pv</option>
      }
    }
    </select>

    Any ideas how to achieve what Lee has done using Razor?

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Jul 27, 2011 @ 01:43
    Nik Wahlberg
    0

    Hey Sean, you can check out the Wiki here. Should work...

    http://our.umbraco.org/wiki/reference/umbracolibrary/getprevalueasstring

    Cheers.

  • Vladimir Knobel 95 posts 171 karma points
    Apr 09, 2012 @ 23:18
    Vladimir Knobel
    1

    @Sean:

    You can't iterate directly the object given back by umbraco.library.GetPreValues(), it's a XPathNodeIterator

    you need to iterate the children of it...
    XPathNodeIterator preValues = umbraco.library.GetPreValues(yourDataTypeId);
     @foreach (XPathNavigator section in preValues) { foreach (XPathNavigator child in section.SelectChildren("preValue", "")) { <option value="@child.Value">@child.Value</option> } }
  • Vladimir Knobel 95 posts 171 karma points
    Apr 09, 2012 @ 23:20
  • 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