5

我目前正在启动一个使用 ASP.NET MVC 的项目,并且想使用 NHaml 作为我的视图引擎,因为我喜欢 Rails/Merb 的 Haml。我面临的主要问题是我的页面布局。在 Webforms 中,我会在头部放置一个 ContentPlaceHolder,以便其他页面可以有特定的 CSS 和 JavaScript 文件。

在 Rails 中,这是使用 yield 和 content_for 完成的

文件:application.haml

%html
  %head
    - yield :style

文件:page.haml

- content_for :style do 
  / specific styles for this page

在 NHaml 中,我可以使用局部变量来执行此操作,但是任何局部变量对于整个控制器文件夹都是全局的。

文件:application.haml

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

文件:_Style.haml

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

有谁知道让 NHaml 在 Rails 场景中工作的方法?

4

2 回答 2

2

在母版页中使用 ^ 评估器,并在每个布局(内容页面)中设置它的值。

请参阅Google Code上的NHaml 示例

于 2009-01-31T20:31:20.987 回答
0

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

于 2009-08-06T11:02:13.600 回答