Copied to clipboard

Flag this post as spam?

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


  • Jeremy Drouin 9 posts 29 karma points
    Jan 27, 2012 @ 22:12
    Jeremy Drouin
    0

    Loop through datatype on template page

    I am trying to loop through a checkbox datatype on a template page, however it will not return any results. Not really sure the best way to go about it. If I use umbraco:Item, it returns a comma listing of the boxes that are checked in the datatype, which is not terribly useful.

    <umbraco:Item field="departmentOptions" stripParagraph="true" runat="server"></umbraco:Item>

    this returns: Upcoming Events,Department Services,Our Staff

    Trying to use XSL does not return anything:
    <xsl:for-each select="umbraco.library:GetPreValues(departmentOptions)//preValue">

       value: <xsl:value-of select="." /><br/>
    </xsl:for-each>

     

     

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 27, 2012 @ 22:40
    Tom Fulton
    1

    Hi,

    Did you try $currentPage/departmentOptions?  If you're not already inside a loop or match template you'll want to prepend $currentPage.

    -Tom

  • Jeremy Drouin 9 posts 29 karma points
    Jan 27, 2012 @ 22:49
    Jeremy Drouin
    0

    Im on a template page,  not an an xslt doc. How do you use $currentPage on a template?

     

  • Rodion Novoselov 694 posts 859 karma points
    Jan 30, 2012 @ 03:22
    Rodion Novoselov
    1

    Hi, Jeremy. If you very much want to get it straight into template along with some transformation you can do it with an inline macro.

    For instance like this:

     

    <umbraco:Macro runat="server" Language="cshtml">
      <ul>
          @foreach(var item in Model.YourCheckboxListField.Split(','))
           {
               <li>@item</li>
           }
       </ul>
    </umbraco:Macro>

    However, personally, I always stand out against this approach. For my taste using inline macros sounds like mixing presentation (templates) with logic (macro code). I'd better write the same down to the usual separate macro and put in into the template through its alias.

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 30, 2012 @ 06:39
    Jeroen Breuer
    1

    Btw Rodion's example only works for Razor, not XSLT. If you want inline XSLT you need to download this package: http://our.umbraco.org/projects/backoffice-extensions/xslt-macro-engine

    Jeroen

  • Rodion Novoselov 694 posts 859 karma points
    Jan 30, 2012 @ 07:08
    Rodion Novoselov
    0

    Yes, I'm aware of it. Afaik also Xslt can also be embeded into an <umbraco:Item> control through the Xslt property, however I've never used it. It doesn't matter anyway - as I said above for me it looks hideous in both cases :-)

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 30, 2012 @ 09:25
    Jeroen Breuer
    0

    I also prefer XSLT in a macro :). Just wanted to point out there was another option to use XSLT.

    Jeroen

     

  • Jeremy Drouin 9 posts 29 karma points
    Jan 30, 2012 @ 15:27
    Jeremy Drouin
    0

    this is by no means pretty, but I ended up doing this:

    <
       var boxes umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("departmentOptions").Value;
       string[] boxArray boxes.Split( ',' );

       if(boxArray.Contains("Upcoming Events")){ %>
       <umbraco:Macro Alias="Department_UpcomingEvents" runat="server" />
    <%>

Please Sign in or register to post replies

Write your reply to:

Draft