简体   繁体   中英

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?

Also, i've read that you'd need to intercept requests for Sass and manually call the builder for it?

Question somewhat duplicated with the answer here: Can NHaml be used as a general purpose template engine? (outside of MVC)

Quote:

Yes, it can be used without 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).

Check out how I use it here: 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));

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

= typeof (BaseClassForTemplates);

 //class providing content to the engine, should implement 

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. You could process NHaml templates even in a console application if you will.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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