From the nhaml perspective
Nhaml view (274 chars)
%h2= ViewData.CategoryName
%ul
- foreach (var product in ViewData.Products)
%li
= product.ProductName
.editlink
= Html.ActionLink("Edit", new { Action="Edit" ID=product.ProductID })
= Html.ActionLink("Add New Product", new { Action="New" })
aspx view (665 chars)
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="List.aspx" Inherits="MvcApplication5.Views.Products.List" Title="Products" %>
<asp:Content ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<h2><%= ViewData.CategoryName %></h2>
<ul>
<% foreach (var product in ViewData.Products) { %>
<li>
<%= product.ProductName %>
<div class="editlink">
(<%= Html.ActionLink("Edit", new { Action="Edit", ID=product.ProductID })%>)
</div>
</li>
<% } %>
</ul>
<%= Html.ActionLink("Add New Product", new { Action="New" }) %>
</asp:Content>
It does this through a series of shorthand characters. See here for a full list [http://code.google.com/p/nhaml/wiki/NHamlLanguageReference]
better to look here [http://code.google.com/p/nhaml/wiki/PartialsAndLayouts]
from the spark perspective
- embedded code into the xml tags and custom code tags can be used to perform progromattic actions. This all allows spark to minimise the context switching that occurs for both nhaml and aspx.
for example this spark
<viewdata products="IEnumerable[[Product]]"/>
<ul if="products.Any()">
<li each="var p in products">${p.Name}</li>
</ul>
<else>
<p>No products available</p>
</else>
aspx and nhaml would require you do a context swtich out to code to perform the if..else statement.
References
[http://code.google.com/p/nhaml/wiki/NHamlLanguageReference]
[http://sparkviewengine.com/documentation/syntax]