Copied to clipboard

Flag this post as spam?

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


  • Streety 358 posts 568 karma points
    Sep 12, 2013 @ 18:04
    Streety
    0

    Conversions to Razor issues.

    Hi I am converting an old XSLT script to rasor and I am stuck on the syntax, any pointers would be gratefully received.

    This is the section (in XSLT) I need to convert:

    Basically I get a reference to the current node:

    <xsl:variable name="nodeIds" select="umbraco.library:Split($currentPage/refreshCarousel,',')" />
    

    then I for each through the values:

    <xsl:for-each select="$nodeIds/value">
    

    ...in a ul li

                <xsl:choose>
              <xsl:when test="$nodeIds/value != '' or $nodeIds/value &gt; 0">
                  <xsl:variable name="slide" select="umbraco.library:GetXmlNodeById(current()/.)"/>
    

    How does this translate to Razor?

    Thanks

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 12, 2013 @ 20:50
    Dennis Aaen
    0

    Hi Streety,

    Maybe this post can help you in the right direction to convert your XSLT code to Razor

    http://our.umbraco.org/forum/developers/razor/30232-razor-and-contains

    /Dennis

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Sep 12, 2013 @ 21:17
    Dan Diplo
    0

    Should be something like this:

    @{
        var nodeIds = Model.Content.GetPropertyValue<string>("refreshCarousel").Split(',');
    
        foreach (string node in nodeIds)
        {
            int id;
    
            <ul>
    
            @if (int.TryParse(node, out id))
            {
                var slide = Umbraco.TypedContent(id);
    
                <li>
                    @slide.Name
                </li>
            }
    
            </ul>
        }
    }
    
    Obviously output whatever you want in the <li> part.
  • Streety 358 posts 568 karma points
    Sep 17, 2013 @ 18:09
    Streety
    0

    Thank you I'll try this.

    Regards

  • Streety 358 posts 568 karma points
    Sep 17, 2013 @ 18:22
    Streety
    0

    Hmmm, is this code for the MVC version. Sorry I am 4.11.x

    Missing assembly:

    The type or namespace name 'TypedContent' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
    
  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Sep 17, 2013 @ 21:13
    Dan Diplo
    0

    Yeah, the code is for a Partial view. If you are using an old macroscript then it would be something like (from memory)

    @{
       
    var nodeIds =CurrentModel.GetPropertyValue("refreshCarousel").Split(',');

       
    foreach(string node in nodeIds)
       
    {
           
    int id;

           
    <ul>

           
    @if(int.TryParse(node,out id))
           
    {
               
    var slide =Library.NodeById(id);

               
    <li>
                   
    @slide.Name
               
    </li>
            }

            </
    ul>
       
    }
    }

    . Hopefully that should be close enough :)

Please Sign in or register to post replies

Write your reply to:

Draft