问题描述
我目前正在启动一个使用ASP.NET MVC的项目,并希望将NHaml用作我的视图引擎,因为我喜欢Rails/Merb的Haml.我面临的主要问题是页面的布局.在Webforms中,我会将ContentPlaceHolder放在头部,以便其他页面可以具有特定的CSS和JavaScript文件.
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.
在Rails中,这是通过yield和content_for
In Rails, this is done utilizing yield and content_for
文件:application.haml
File: application.haml
%html
%head
- yield :style
文件:page.haml
File: page.haml
- content_for :style do
/ specific styles for this page
在NHaml中,我可以使用局部函数来进行此操作,但是对于整个控制器文件夹而言,任何局部变量都是全局的.
In NHaml, I can do this with partials, however any partials are global for the entire controller folder.
文件:application.haml
File: application.haml
!!!
%html{xmlns="http://www.w3.org/1999/xhtml"}
%head
_ Style
文件:_Style.haml
File: _Style.haml
%link{src="http://www.thescore.com/css/style.css?version=1.1" type="text/css"}
有人知道让NHaml在Rails场景中工作的方法吗?
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.
这篇关于NHaml是否具有content_for布局功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!