views:

862

answers:

2

I am currently starting a project utilizing ASP.NET MVC and would like to use NHaml as my view engine as I love Haml from Rails/Merb. The main issue I face is the laying out of my pages. In Webforms, I would place a ContentPlaceHolder in the head so that other pages can have specific CSS and JavaScript files.

In Rails, this is done utilizing yield and content_for

File: application.haml

%html
  %head
    - yield :style

File: page.haml

- content_for :style do 
  / specific styles for this page

In NHaml, I can do this with partials, however any partials are global for the entire controller folder.

File: application.haml

!!!
%html{xmlns="http://www.w3.org/1999/xhtml"}
  %head
    _ Style

File: _Style.haml

%link{src="http://www.thescore.com/css/style.css?version=1.1" type="text/css"}

Does anyone know of a way to get NHaml to work in the Rails scenario?

+2  A: 

Use the ^ evaluator in the master page, and set it's value in each of the layouts(content pages).

See NHaml Samples from it's source on Google Code.

Parsa
A: 

The "content placeholders" are not yet supported.
But there is a request for that.

You can vote for it too

BUT this is how I provided per-page content in NHAML:
http://dnagir.blogspot.com/2009/07/nhaml-scripts-and-styles-code-block.html

Dmytrii Nagirniak