Morestachio 2.2.56
See the version list below for details.
dotnet add package Morestachio --version 2.2.56
NuGet\Install-Package Morestachio -Version 2.2.56
<PackageReference Include="Morestachio" Version="2.2.56" />
paket add Morestachio --version 2.2.56
#r "nuget: Morestachio, 2.2.56"
// Install Morestachio as a Cake Addin #addin nuget:?package=Morestachio&version=2.2.56 // Install Morestachio as a Cake Tool #tool nuget:?package=Morestachio&version=2.2.56
<img src="http://assets.wildbit.com/postmark/misc/Morestachio-logo@2x.png" alt="Morestachio Logo" title="Pistachio + Mustache => Morestachio" width="148" height="149">
Morestachio
A Lightweight, powerful, flavorful, templating engine for C# and other .net-based languages.
What's this for?
Morestachio allows you to create simple text-based templates that are fast and safe to render. It's the heart of Postmark Templates, and we're ecstatic to provide it as Open Source to the .net community.
How to use Morestachio:
// Parse the template:
var sourceTemplate = "Dear {{name}}, this is definitely a personalized note to you. Very truly yours, {{sender}}"
var template = Morestachio.Parser.Parse(sourceTemplate);
// Create the values for the template model:
dynamic model = new ExpandoObject();
model.name = "John";
model.sender = "Sally";
// Combine the model with the template to get content:
var content = template(model);
Installing Morestachio:
Morestachio can be installed via NuGet:
Install-Package Morestachio
Key differences between Morestachio and mustachio
Morestachio is build upon Mustachio and extends the mustachio syntax in a few ways.
- each value can be formatted by adding formatter the the morestachio
- Templates will be parsed as streams and will create a new stream. This is better when creating larger templates and best for web as you can also limit the length of the "to be" created template to a certain size
- Morestachio accepts any object besides the Dictionary<string,object> from mustachio.
Key differences between Morestachio and Mustache
Morestachio contains a few modifications to the core Mustache language that are important.
each
blocks are recommended for handling arrays of values. (We have a good reason!)- Complex paths are supported, for example
{{ this.is.a.valid.path }}
and{{ ../this.goes.up.one.level }}
- Template partials (
{{> secondary_template }}
) are not supported. (We have a good reason!)
A little more about the differences:
One awesome feature of Morestachio is that with a minor alteration in the mustache syntax, we can infer what model will be required to completely fill out a template. By using the each
keyword when interating over an array, our parser can infer whether an array or object (or scalar) should be expected when the template is used. Normal mustache syntax would prevent us from determining this.
We think the model inference feature is compelling, because it allows for error detection, and faster debugging iterations when developing templates, which justifies this minor change to 'vanilla' mustache syntax.
Template partials are a great feature for large scale template development. However, they introduce the risk of infinite recursion if used improperly (especially since Morestachio allows for one to navigate 'up' a model with ../
).
In our use case (email templating), including partials would complicate the general process of creating the templates, and allow unknown users to create potentially unbound processing requirements on our servers. It is possible to detect these cycles while parsing templates, so, if this is important to our customers, or the broader OSS community, partial template support may be added to Morestachio in the future.
Infos about new features
Its now possible to add plain objects to the Dictionary. They will be called by reflection. Also you can now spezify the excact Size of the template to limit it (this could be come handy if you are in a hostet env). Also there is a new Operator {{?}}. Use it the access the current value direct. This will invoke ToString on the object in the current scope. Its good for cases where you are looping through a collection of primitives like:
{{#each Data.ArrayOfInts}} Current int: {{?}} {{/each}}
Formatter
Use the ContextObject.PrintableTypes collection to create own formatter for your types or add one to the new ParserOptions object for just one call. To invoke them in your template use the new Function syntax: {{Just.One.Formattable(AnyStringFormat).Thing}}
The formatter CAN return a new object on wich you can call new Propertys or it can return a string. There are formatter prepaired for all Primitve types. That means per default you can call on an object hat contains a DateTime:
{{MyObject.DateTime(D)}}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
- Newtonsoft.Json (>= 11.0.2)
NuGet packages (9)
Showing the top 5 NuGet packages that depend on Morestachio:
Package | Downloads |
---|---|
Morestachio.Newtonsoft.Json
Package Description |
|
Morestachio.Linq
The Linq Formatters that require complex arguments for the Morestachio nuget package |
|
Morestachio.LessCompiler
A powerfull c# infused templating engine. |
|
Morestachio.Runner
Package Description |
|
Morestachio.System.Xml.Linq
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
5.0.1.631 | 19,888 | 8/1/2022 |
5.0.1.622 | 2,697 | 6/23/2022 |
5.0.1.615 | 2,517 | 6/15/2022 |
5.0.1.613 | 2,989 | 6/15/2022 |
5.0.1.589 | 1,817 | 5/12/2022 |
5.0.1.570 | 3,240 | 4/9/2022 |
5.0.1.534 | 5,806 | 10/20/2021 |
5.0.0.513 | 2,389 | 5/2/2021 |
5.0.0.504 | 1,525 | 3/3/2021 |
5.0.0.503 | 721 | 2/24/2021 |
5.0.0.487 | 735 | 2/18/2021 |
4.3.3.480 | 840 | 1/27/2021 |
4.3.3.478 | 718 | 1/14/2021 |
4.3.2.476 | 735 | 1/14/2021 |
4.3.2.472 | 976 | 1/12/2021 |
4.3.2.460 | 731 | 1/3/2021 |
4.3.2.459 | 694 | 12/29/2020 |
4.3.2.457 | 837 | 12/4/2020 |
4.3.2.450 | 790 | 11/3/2020 |
4.3.2.441 | 1,041 | 10/28/2020 |
4.3.1.413 | 808 | 9/26/2020 |
4.3.0.405 | 949 | 9/11/2020 |
4.3.0.397 | 802 | 9/4/2020 |
4.3.0.392 | 798 | 8/24/2020 |
4.2.0.376 | 912 | 8/8/2020 |
4.0.1.374 | 814 | 8/8/2020 |
4.0.1.367 | 872 | 7/28/2020 |
4.0.1.355 | 796 | 7/24/2020 |
4.0.1.342 | 714 | 7/16/2020 |
4.0.1.332 | 2,211 | 6/30/2020 |
4.0.1.323 | 532 | 6/30/2020 |
4.0.0-alpha2 | 366 | 6/18/2020 |
4.0.0-alpha1 | 492 | 6/13/2020 |
3.0.1 | 1,630 | 3/16/2020 |
3.0.0 | 566 | 3/9/2020 |
3.0.0-alpha7 | 442 | 1/9/2020 |
3.0.0-alpha6 | 477 | 1/9/2020 |
3.0.0-alpha5 | 472 | 1/9/2020 |
3.0.0-alpha4 | 421 | 11/10/2019 |
3.0.0-alpha3 | 399 | 11/9/2019 |
3.0.0-alpha2 | 391 | 11/6/2019 |
3.0.0-alpha1 | 381 | 11/2/2019 |
2.3.8 | 7,892 | 10/31/2019 |
2.3.7 | 582 | 10/24/2019 |
2.3.6 | 1,217 | 10/16/2019 |
2.3.5 | 585 | 9/6/2019 |
2.3.4 | 587 | 9/5/2019 |
2.3.3 | 632 | 8/24/2019 |
2.3.2 | 625 | 8/24/2019 |
2.3.1 | 629 | 8/23/2019 |
2.3.0 | 630 | 8/11/2019 |
2.2.135 | 745 | 12/24/2018 |
2.2.134 | 730 | 12/23/2018 |
2.2.133 | 724 | 12/23/2018 |
2.2.132 | 719 | 12/18/2018 |
2.2.131 | 710 | 12/18/2018 |
2.2.130 | 760 | 12/1/2018 |
2.2.129 | 765 | 12/1/2018 |
2.2.121 | 843 | 10/2/2018 |
2.2.120 | 848 | 9/29/2018 |
2.2.119 | 865 | 9/27/2018 |
2.2.118 | 841 | 9/27/2018 |
2.2.117 | 836 | 9/27/2018 |
2.2.116 | 797 | 9/27/2018 |
2.2.115 | 812 | 9/26/2018 |
2.2.114 | 810 | 9/26/2018 |
2.2.111 | 834 | 9/25/2018 |
2.2.110 | 940 | 9/25/2018 |
2.2.108 | 830 | 9/25/2018 |
2.2.107 | 834 | 9/25/2018 |
2.2.106 | 829 | 9/25/2018 |
2.2.105 | 844 | 9/25/2018 |
2.2.104 | 820 | 9/25/2018 |
2.2.91 | 1,004 | 9/23/2018 |
2.2.90 | 827 | 9/23/2018 |
2.2.82 | 844 | 9/12/2018 |
2.2.60 | 851 | 9/12/2018 |
2.2.56 | 1,073 | 9/12/2018 |