A file system based template content provider for Handlebars.Core.
nuget install Handlebars.ContentProvider.FileSystem
var engine = new HandlebarsEngine();
engine.Configuration.TemplateContentProvider = new FileSystemTemplateContentProvider();
var template = engine.CompileView("foo.hbs");
To provide backward compatibility to the ViewEngine concept of the original Handlebars.Net library,
you need to set PartialsSubPath
:
var fileSystemTemplateContentProvider = new FileSystemTemplateContentProvider();
fileSystemTemplateContentProvider.PartialsSubPath = "partials";
This will allow you to keep your views to be in the /Views folder like so:
Views\layout.hbs |<--shared as in \Views
Views\partials\somepartial.hbs <--shared as in \Views\partials
Views\{Controller}\{Action}.hbs
Views\{Controller}\{Action}\partials\somepartial.hbs
But it will also find partials if there are at the same level as the as the actual template file:
Views\layout.hbs
Views\someotherpartial.hbs
Pull requests are welcome! The guidelines are pretty straightforward:
- Only add capabilities that are already in the Mustache / Handlebars specs
- Avoid dependencies outside of the .NET BCL
- Maintain cross-platform compatibility (.NET/Mono; Windows/OSX/Linux/etc)
- Follow the established code format