Does NHaml have a content_for ability for layouts?

拟墨画扇 提交于 2019-12-07 04:03:56

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/127267/does-nhaml-have-a-content-for-ability-for-layouts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!