Code Monkey home page Code Monkey logo

handlebars.net.mvc's Introduction

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.
  var hbsve = new HandlebarsViewEngine();
  
  // 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 engine
  ViewEngines.Engines.Add(hbsve);

Example

controller

public class HomeController : Controller
{
  public ActionResult Index()
  {
    var model = 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>

handlebars.net.mvc's People

Contributors

jiellse avatar

Stargazers

 avatar  avatar  avatar

Forkers

ktice12 fhogberg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.