Tuesday, December 28, 2010

Razor for MVC in Sitecore

Like Peter in his comment to Alex' blog here, I'm also not a big fan of XLST's. I've seen several discussions about (not) using XSLT's in Sitecore with good arguments and even Sitecore has arguments for both. Fact remains, not all the people involved in Sitecore projects know asp.net, could the new Razor syntax in MVC be a viable solution here?
Is the following code fragment easier than it's XSLT counterpart?
 <ul>  
@foreach (var aChild in Item.Children.Where(Child => Child["ShowInMenu"] != "0"))  
{  
<li>@aChild.Name</li>  
}  
</ul>  

That is a simple sample, but what about "Creating a tree like left menu"? In XSLT Brian Pedersen does it like this, a very good sample. What would that look like in Razor? A simple sample, without reuse/recursion:
 <ul>  
@foreach (var aChild in Item.Children.Where(Child => Child["ShowInMenu"] != "0"))  
{  
<li>@aChild.Name  
<ul>  
@foreach (var bChild in aChild.Children.Where(Child => Child["ShowInMenu"] != "0"))  
{  
<li>@bChild.Name</li>  
}  
</ul>  
</li>  
}  
</ul>  


Is this something people would like in favor of XSLT's? The guys at Sitecore could add some helpers, modelbinders and stuff like that to make MVC even easier (They might be working on it right now), is a LINQ query easier to understand that XPATH?
Would this make Sitecore development even more productive?
I think so, do you? 

1 comment:

  1. Why don't you give it a try? I created a module that allows for Razor templates to be integrated into Sitecore. I'd really like to hear your opinion! Check out the following url: http://dotnetminute.blogspot.com/2011/06/razorforsitecore-module-enable-razor.html

    ReplyDelete