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?
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 .
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.