Skip to content

Latest commit

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Handlebars.Net.Mvc

An ASP.NET MVC ViewEngine using the Handlebars syntax.

About

This project uses https://github.com/rexm/Handlebars.Net to compile the view files on the server to .NET bytecode. The syntax for the view files is described at http://handlebarsjs.com/ (but note that is client-side Javascript so some parts differ).

Documentation

The API documentation exists at https://jiellse.github.io/Handlebars.Net.Mvc/

Bootstrapping

In Application_Start in Global.asax.cs add the following lines:

// In case you want to remove the other view engines, do this:ViewEngines.Engines.Clear();// Create the view engine.varhbsve=newHandlebarsViewEngine();// The builtin helpers aren't added by default - you need to opt-in to have them available.hbsve.RegisterMvcHelpers();hbsve.RegisterSectionsHelpers();// Add the Handlebars view engineViewEngines.Engines.Add(hbsve);

Example

controller

publicclassHomeController:Controller{publicActionResultIndex(){varmodel=new{first="John",last="Doe"}
return View(model);}}

View file (~/Views/Home/Index.hbs)

{{!< default}}
Hello, {{first}} {{last}}!

Layout file (~/Views/_Layouts/default.hbs)

<html><body>
{{{body}}}
</body></html>

Renders:

<html><body>
Hello, John Doe!
</body></html>

About

An ASP.NET MVC ViewEngine using the Handlebars syntax

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages