Just to recap – I’m looking for a view engine that will allow a web designer to create the views on my behalf, or at the very least work closely with the developers in terms of styling and layout. The default ASP.NET view engine is simply not sufficient in this regard – the design was always aimed at developers, not designers. On a higher level, projects like MVC Contrib are making this problem even worse. Don’t get me wrong – I like MVC Contrib. I’m simply making the point that while we are making development easier for developers, we are making it harder for designers to work with developers.
If you don’t believe me, go ask a designer to style this table.
I had a quick look at the different view engines available to see if any of them could help us in the right direction.
NHaml is part of MVC Contrib and uses Haml syntax from Ruby.
Thanks to Scott Hanselman for the snippet. Clearly this is not what I’m looking for.
The syntax is certainly different and very html friendly (the Spark motto is “Html friendly – Less is more”). However it’s still not what I’m looking for – while a designer would find the syntax reasonably familiar, I’m convinced that mixing html with evaluated code in this manner is not helping our cause in this regard.
My initial impression of NVelocity was very positive. There seems to be very little information available for this view engine, but a couple of the examples looked very promising. Here is what a foreach loop looks like.
Which is very much what I’m looking for. However, take a look at the following snippet.
And we’re back to square one. Or even worse:
Finally, an answer
I completely understand why most view engines have complex syntax – we are trying to duplicate the functionality from the default ASP.NET view engine. A developer isn’t going to use a view engine if it can’t do everything the built-in one can do, right? Well, not necessarily…
I was immediately impressed by the syntax. Presentation logic is clearly separated from the actual html and it’s painfully obvious what is evaluated code and what’s not. There are even modifiers to allow a designer to specify that a variable must be displayed in upper- or lowercase or to specify the datetime format. I had a look at most of the functions and became convinced that this is exactly what I’m looking for.
There’s only one major problem – it’s a php view engine.
Writing my own view engine
I wanted to experiment and see if I could write a view engine (for ASP.NET) that uses the same syntax. I found it surprisingly simple in some areas and surprisingly difficult in others. It took me about an hour to be able to render a foreach statement (and another hour to be able to render nested foreach statements). The tricky part is in structuring the code and allowing different kinds of functions (at the moment you should be able to add your own functions as well).
So this is where I am at the moment – I first want to try and structure the code a little better and at least implement all the functions that Smarty supports by default. More on this will follow.
On a personal note
I usually don’t mention personal details in my blog, but I’m going to make an exception here. I won’t be doing any blogging for at least 2 weeks since I’m off to London and Europe during which time I’m going to watch the Belgian Grand Prix.