{"id":19665547,"url":"https://github.com/geeklearningio/gl-dotnet-templating","last_synced_at":"2026-05-03T22:32:19.375Z","repository":{"id":56589411,"uuid":"58205546","full_name":"geeklearningio/gl-dotnet-templating","owner":"geeklearningio","description":".NET Core Templating abstractions with Handlebars and Mustache.js providers","archived":false,"fork":false,"pushed_at":"2020-10-29T22:43:23.000Z","size":63,"stargazers_count":3,"open_issues_count":6,"forks_count":0,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-02-27T03:50:28.514Z","etag":null,"topics":["dotnet","dotnet-core","handlebars","partials","template-engine"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geeklearningio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-06T12:25:11.000Z","updated_at":"2020-10-29T22:32:31.000Z","dependencies_parsed_at":"2022-08-15T21:31:11.431Z","dependency_job_id":null,"html_url":"https://github.com/geeklearningio/gl-dotnet-templating","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/geeklearningio/gl-dotnet-templating","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geeklearningio%2Fgl-dotnet-templating","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geeklearningio%2Fgl-dotnet-templating/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geeklearningio%2Fgl-dotnet-templating/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geeklearningio%2Fgl-dotnet-templating/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geeklearningio","download_url":"https://codeload.github.com/geeklearningio/gl-dotnet-templating/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geeklearningio%2Fgl-dotnet-templating/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278717449,"owners_count":26033542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet","dotnet-core","handlebars","partials","template-engine"],"created_at":"2024-11-11T16:23:23.714Z","updated_at":"2025-10-07T03:54:51.685Z","avatar_url":"https://github.com/geeklearningio.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NuGet Version](http://img.shields.io/nuget/v/GeekLearning.Templating.svg?style=flat-square\u0026label=NuGet)](https://www.nuget.org/packages/GeekLearning.Templating/)\n[![Build Status](https://geeklearning.visualstudio.com/_apis/public/build/definitions/f841b266-7595-4d01-9ee1-4864cf65aa73/24/badge)](#)\n\n# gl-dotnet-templating\n\nThis templating library is an abstraction above various templating engines and our \n[storage library](https://github.com/geeklearningio/gl-dotnet-storage). It handles loading\nfrom any location supported by our storage library. It will also transparently cache templates \nfor you. \n\nIt has support for partials, files prefixed with an underscore `_` will be considered as partials\nand loaded as such.\n\n## Getting started\n\nIn your project.json add required dependencies :\n```\n\"GeekLearning.Storage.FileSystem\": \"0.5.0\",\n    \n\"GeekLearning.Templating\": \"0.5.0\",\n\"GeekLearning.Templating.Handlebars\": \"0.5.0\",\n```\n\nThen add required settings in your `appsettings.json` file. In this example, we will\nuse FileSystem provider to configure a storage provider which will load files from\na `Templates` folder relative to Application Root. This could be configured to use \nan Azure Container instead (see storage documentation).\n\n```json\n\"Storage\": {\n    \"Stores\": {\n      \"Templates\": {\n        \"Provider\": \"FileSystem\",\n        \"Parameters\": {\n          \"Path\": \"Templates\"\n        }\n      }\n    }\n  }\n```\n\nWe will then create an `EmailTemplates` class. It will be based on `TemplateCollectionBase`\nwhich eliminates most of the boilerplate code required to load and execute a template. \n\n```csharp\npublic class EmailTemplates : TemplateCollectionBase\n{\n    public EmailTemplates(IStorageFactory storageFactory, ITemplateLoaderFactory templateLoaderFactory) : base(\"Templates\", storageFactory, templateLoaderFactory)\n    {\n\n    }\n\n    public Task\u003cstring\u003e ApplyInvitationTemplate(InvitationContext context)\n    {\n        return this.LoadAndApplyTemplate(\"invitation\", context);\n    }\n\n    public Task\u003cstring\u003e ApplyInvitation2Template(InvitationContext context)\n    {\n        return this.LoadAndApplyTemplate(\"invitation2\", context);\n    }\n\n    public Task\u003cstring\u003e ApplyInvitation3Template(InvitationContext context)\n    {\n        return this.LoadAndApplyTemplate(\"SubDir/invitation\", context);\n    }\n}\n```\n\nThen in your `Startup.cs` file add required dependencies and configuration to the DI container. \n\n```csharp\nservices.AddMemoryCache();\nservices.AddStorage().AddFileSystemStorage(HostingEnvironment.ContentRootPath).AddAzureStorage();\nservices.AddTemplating().AddMustache().AddHandlebars();\nservices.AddScoped\u003cEmailTemplates\u003e();\n\nservices.Configure\u003cStorageOptions\u003e(Configuration.GetSection(\"Storage\"));\n```\n\n## Templating Abstraction\n\nOur abstraction is composed of a few interface and a base class to reduce boilerplate code when\nworking with templates.\n\nFirst interface is `ITemplateLoaderFactory`.\n\n```csharp\npublic interface ITemplateLoaderFactory\n{\n    ITemplateLoader Create(IStore store);\n}\n```\n\nYou can use this interface to get an `ITemplateLoader` for a specific `IStore` (see storage documentation)\n\n```csharp\npublic interface ITemplateLoader\n{\n    Task\u003cITemplate\u003e GetTemplate(string name);\n}\n```\n\nOnce you have an `ITemplateLoader` interface you can retrieve a specific template by is name.\nIf it's not already loaded, it will be read from the `IStore`.\n\n```csharp\npublic interface ITemplate\n{\n    string Apply(object context);\n}\n```\n\nA `ITemplate` reference can be executed on a specific `context` using `Apply` method.\n\n## Handlebars provider\n\n`Handlebars` provider allows you to load `.hbs` templates \n(see [Handlebars.js](http://handlebarsjs.com/)). It relies on Handlebars.Net [port](https://github.com/rexm/Handlebars.Net).\n\nThis is our recommanded option as it compiles templates for better performance.\n\n## Mustache.js provider\n\n`Mustache.js` provider is a mustache provider allowing you to load `.mustache` templates. It is based on \n[mustache sharp](https://github.com/jehugaleahsa/mustache-sharp) work. As we've go no answer\nfrom author, we are maintaining dotnet core support on our [own fork](https://github.com/sandorfr/mustache-sharp).\n\nA good thing is it has no dependency on Emit or Expression so it might be usefull on some\nedge cases. \n\n**Note that it does not support partials.**\n\n## Roadmap\n\n* Design and add Helpers support for Handlebars Engine.\n* Additional providers (haml through NHAML or NVelocity).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeeklearningio%2Fgl-dotnet-templating","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeeklearningio%2Fgl-dotnet-templating","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeeklearningio%2Fgl-dotnet-templating/lists"}