Copied to clipboard

Flag this post as spam?

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


  • phenryll 28 posts 53 karma points
    Dec 27, 2010 @ 13:34
    phenryll
    5

    Razor with Umbraco 4.6 - Thumbs up! - Razor and Xslt

    This morning I was reading Slace's blog entry about Razor in Umbraco 4.6 If you didn't you should:

    http://www.aaron-powell.com/umbraco-4-and-razor

    Razor is the new view engine that ships with MVC 3. Scott Guthrie talked a lot about Razor for MVC3. He mentionned that Razor would be available for webforms as well, but later...

    >>>>>>>>> Its a sad day for us WebForms developers that such a thing wont exist there or so I think because you havent talked about that in the post atleast,so how can we use it in Web Forms?

    You'll be able to use .cshtml/.vbhtml files within web forms based applications as well. Stay tuned.

    Hope this helps,

    Scott (http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx)

    Well, the Umbraco team did a fantastic job for integrating Razor in our favorite webforms CMS. The team did it well before S. Guthrie blog about it ;o)

    In short: Well done!

    One question: I love Xslt. I am wondering if they are scenario where Xslt is more appropriate than using Razor. Xslt is not a programming language while you can take advantage of C# when using Razor (Well Xslt has Xslt extensions).

    A part from the comfort of having several options, is there any scenarios where Xslt is the way to go when doing template stuff?

    Xslt is deemed to be very fast. How fast is Razor compared to Xslt?

    Thanks for reading.

    Roland

     

     

  • Dan 1285 posts 3917 karma points c-trib
    Jan 04, 2011 @ 15:27
    Dan
    1

    As far as I understand, it's not possible currently to traverse the content tree with Razor, so won't be too good at creating nested navigation lists etc.  So for the time-being at least, I'll be building my site navigation with XSLT.  No doubt this will change.

  • Jonas Eriksson 930 posts 1825 karma points
    Jan 04, 2011 @ 19:15
    Jonas Eriksson
    4

    Using common cs-code, linq2sql or old friend Nodefactory, it's indeed possible to do some traversing.

    @using umbraco.presentation.nodeFactory
    @foreach (Node c in new Node(1050).Children)
    {
      <li>@c.Name</li>
    }

    And the functions-syntax makes it possible to add functions aswell (for recursiveness):

    @functions
    {
       string traverse(int nodeid)
       {
         ...
       }
    }

    I also want to place a bet for the good use of uComponents.uQuery here as I understand it's a set of helper functions for (among other things?) finding & traversing both content and media nodes.

    Regards

    Jonas

  • Jonas Eriksson 930 posts 1825 karma points
    Jan 04, 2011 @ 20:26
    Jonas Eriksson
    2

    hm... problems with the tags when I try to edit. Here's a quick and dirty full nodestructure ul-li in razor:

    @using umbraco.presentation.nodeFactory           
    @functions
    {
    string traversenodes(int nodeid)
    {
    string retval="";
    Node n = new Node(nodeid);
    if (n.Children.Count>0)
    {
    retval +="<ul>";
    foreach (Node c in n.Children)
    {
    retval += "<li>" + c.Name;
    retval += traversenodes(c.Id);
    retval += "</li>";
    }
    retval +="</ul>";
    }
    return retval;
    }
    }

    <h1>Full sitemap</h1>

    @traversenodes(-1)
  • webmonger 130 posts 285 karma points
    Jan 04, 2011 @ 20:33
    webmonger
    0

    Thanks for the help guys. I'll continue to investigate and do some prototyping as well.

    Does anyone have any comments on the Speed question? XSLT can be cached too is it possible to cache razor templates?

    Cheers

    Jon

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jan 04, 2011 @ 22:53
    Aaron Powell
    0

    There's currently no caching on Razor templates.

    The currentPage object which is being passed into the razor template will have an AnccestorOrSelf method on it for the next Juno release (it's in the nightlies) so it'll have more functionality similar to what can be done for XPath

  • webmonger 130 posts 285 karma points
    Jan 04, 2011 @ 23:39
    webmonger
    0

    Thanks Slace. Do you know if Razor is as fast as XSLT? I presume the view engine will be comparable to xslt but is the processing more or less intensive?

    Cheers

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jan 05, 2011 @ 00:46
    Aaron Powell
    0

    I don't know why people are so interested in speed comparisons, you'll be looking at millisecond differences anyway.

    I once compared IronPython to XSLT and it was negligible in terms of performance differences (although IronPython was faster).

  • webmonger 130 posts 285 karma points
    Jan 05, 2011 @ 22:10
    webmonger
    0

    I guess if its working from Memory as the XSLT stuff does then there will be no speed issue. However if the Model was calling the database for example then there would be a speed differnece and i guess this is what i'm talking about really. Is Razor working from the same data held in memory as the XSLT?

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jan 05, 2011 @ 22:38
    Aaron Powell
    0

    Like all other macros it uses the XML cache

Please Sign in or register to post replies

Write your reply to:

Draft