0

无法直接在 NHAML 项目页面上找到它,所以我想知道您是否需要运行 ASP.NET MVC 才能使用 NHaml,或者我是否可以在“普通”ASP.NET 网页上使用它?

另外,我读到你需要拦截对 Sass 的请求并手动调用它的构建器?

4

2 回答 2

1

问题与此处的答案有些重复:可以将 NHaml 用作通用模板引擎吗?(在 MVC 之外)

引用:

是的,它可以在没有 ASP.Net MVC 的情况下使用。我将它用于我自己的 Web 服务器(但这并不意味着您必须将它与 Web 服务器一起使用)。

看看我在这里如何使用它: http ://webserver.codeplex.com/SourceControl/changeset/view/50874#671672

简而言之,您所做的是这样的:

TemplateEngine _templateEngine = new TemplateEngine();

// Add a type used in the template. Needed to that nhaml can

编译模板时找到它 _templateEngine.Options.AddReferences(typeof (TypeInYourAssembly));

// base class for all templates
_templateEngine.Options.TemplateBaseType

= typeof (BaseClassForTemplates);

//class providing content to the engine, should implement

ITemplateContentProvider _templateEngine.Options.TemplateContentProvider = 这个;

// compile the template, 
CompiledTemplate template = _templateEngine.Compile(new List<string> {layoutName, viewPath},
                                                                typeof (TemplateImplementation));

//create a instance
var instance = (NHamlView)template.CreateInstance();

// provide the view data used by the template
instance.ViewData = viewData;

// render it into a text writer
instance.Render(writer);
于 2010-12-22T17:23:58.520 回答
0

不,它不需要 ASP.NET MVC,尽管它有一个实现。如果愿意,您甚至可以在控制台应用程序中处理 NHaml 模板。

于 2010-11-24T08:49:23.350 回答