【发布时间】:2010-11-24 08:42:05
【问题描述】:
无法直接在 NHAML 项目页面上找到它,所以我想知道您是否需要运行 ASP.NET MVC 才能使用 NHaml,或者我是否可以在“普通”ASP.NET 网页上使用它?
另外,我听说您需要拦截对 Sass 的请求并为其手动调用构建器?
【问题讨论】:
标签: nhaml
无法直接在 NHAML 项目页面上找到它,所以我想知道您是否需要运行 ASP.NET MVC 才能使用 NHaml,或者我是否可以在“普通”ASP.NET 网页上使用它?
另外,我听说您需要拦截对 Sass 的请求并为其手动调用构建器?
【问题讨论】:
标签: nhaml
问题与这里的答案有些重复:Can NHaml be used as a general purpose template engine? (outside of MVC)
引用:
是的,它可以在没有 ASP.Net 的情况下使用 MVC。我将它用于我自己的网络服务器 (但这并不意味着你有 将其与 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 implementITemplateContentProvider _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);
【讨论】:
不,它不需要 ASP.NET MVC,尽管它有一个实现。如果愿意,您甚至可以在控制台应用程序中处理 NHaml 模板。
【讨论】: