Sitecore Haml Rendering
Haml is a markup language used to generate XHTML. It was originally created as an alternate view engine for Ruby on Rails and has been ported to .net under the banner NHaml by Andrew Peters.
Haml uses space indentation to determine code blocks, which leads to being very easy to edit in a webform, as you don't need to worry about tab indentation and making sure you close your tags. Haml does it all for you.
Download
Sitecore Haml Rendering 1.0 (74.6k)Haml Rendering 1.0 source (3,233k)
Install
The Haml rendering is distributed as a Sitecore package. Just download the package using the above link and install using the installation wizard in Sitecore.
Uninstall
To uninstall the Haml rendering just delete the following item from the master database:
- /sitecore/layout/Renderings/Haml Rendering
Also, delete the following files:
- \bin\CustomControls.dll
- \bin\NHaml.dll
Build
You can also build the Haml rendering yourself using the above 'source' link. The source is in C# and contains Visual Studio 2008 project and solution files. Just open the solution and build as normal.
The source file above also include a compiled version of NHaml in the 'lib' folder. You can use this library or pull down the latest NHaml source from Andrew's blog.
Usage
The Haml Rendering is registered in Sitecore as a Sitecore web control. To use a Haml rendering for your items presentation, after writing your Haml file and saving it on the file system, just include the Haml Rendering in the list of renderings for that item and set the 'Filename' parameter to the Haml file you wish to use.
Include Haml Rendering in item's presentation
Settings for Haml Rendering
You can also set an optional 'CodeBeside' parameter which is a fully qualified type which will be included in your generated Haml template.
Example Haml
Below are 2 sample Haml files. The first will output information about the current item and it's children. The second will use the code beside to format some of the item's data.
NOTE: The below code uses 2 space characters to indent each level. This is a requirement for NHaml (although this is changing as you read this).
%h1= Sitecore.Context.Item.Name
.content
%p= Sitecore.Context.Item["Text"]
.nav
%p
- foreach(Item i in Sitecore.Context.Item.GetChildren())
%a{href=i.Paths.GetFriendlyUrl()}
=i.Name
%br
%p= Formatter.FormatDate(Sitecore.Content.Item["date"])
References
The following references might be useful in helping you get to know Haml
- Andrew Peter's blog and home to NHaml
- http://andrewpeters.net/
- Launch of NHaml and basic tutorial
- http://andrewpeters.net/2007/12/19/introducing-nhaml-an-aspnet-mvc-view-engine/
- Haml website
- http://haml.hamptoncatlin.com/
- Haml tutorial
- http://haml.hamptoncatlin.com/tutorial/
- Haml documentation
- http://haml.hamptoncatlin.com/docs/