简体   繁体   English

NHAML是否需要ASP.NET MVC?

[英]Does NHAML require ASP.NET MVC?

Couldn't find this directly on the NHAML project page, so i was wondering if you need to run the ASP.NET MVC in order to use NHaml or if I can use this on a "normal" ASP.NET webpage? 无法在NHAML项目页面上直接找到它,所以我想知道您是否需要运行ASP.NET MVC才能使用NHaml还是可以在“常规” ASP.NET网页上使用它?

Also, i've read that you'd need to intercept requests for Sass and manually call the builder for it? 另外,我读到您需要拦截对Sass的请求并手动为其调用构建器?

Question somewhat duplicated with the answer here: Can NHaml be used as a general purpose template engine? 问题在这里与答案有些重复: NHaml可以用作通用模板引擎吗? (outside of MVC) (在MVC之外)

Quote: 引用:

Yes, it can be used without ASP.Net MVC. 是的,它可以在没有ASP.Net MVC的情况下使用。 I use it for my own web server (but that doesn't mean that you HAVE to use it with web servers). 我将其用于自己的Web服务器(但这并不意味着您必须将其用于Web服务器)。

Check out how I use it here: http://webserver.codeplex.com/SourceControl/changeset/view/50874#671672 在这里查看我的用法: http : //webserver.codeplex.com/SourceControl/changeset/view/50874#671672

What you do in short is something like this: 简而言之,您要做的是这样的:

 TemplateEngine _templateEngine = new TemplateEngine(); // Add a type used in the template. Needed to that nhaml can 

find it when compiling the template _templateEngine.Options.AddReferences(typeof (TypeInYourAssembly)); 在编译模板_templateEngine.Options.AddReferences(typeof(TypeInYourAssembly))时找到它;

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

= typeof (BaseClassForTemplates); = typeof(BaseClassForTemplates);

 //class providing content to the engine, should implement 

ITemplateContentProvider _templateEngine.Options.TemplateContentProvider = this; ITemplateContentProvider _templateEngine.Options.TemplateContentProvider = this;

 // 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); 

No, it does not require ASP.NET MVC although there's an implementation for it. 不,尽管有实现,但它不需要ASP.NET MVC。 You could process NHaml templates even in a console application if you will. 您甚至可以在控制台应用程序中处理NHaml模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM