• Stars
    star
    198
  • Rank 196,898 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight, powerful, flavorful, template engine.

Mustachio Logo

Mustachio

Nuget

A Lightweight, powerful, flavorful, templating engine for C# and other .net-based languages.

What's this for?

Mustachio 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 Mustachio:

// Parse the template:
var sourceTemplate = "Dear {{name}}, this is definitely a personalized note to you. Very truly yours, {{sender}}"
var template = Mustachio.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);

Extending Mustachio with Token Expanders:

// You can add support for Partials via Token Expanders.
// Token Expanders can be used to extend Mustachio for many other use cases, such as: Date/Time formatters, Localization, etc., allowing also custom Token Render functions.

var sourceTemplate = "Welcome to our website! {{{ @content }}} Yours Truly, John Smith.";
var stringData = "This is a partial. You can also add variables here {{ testVar }} or use other expanders. Watch out for infinite loops!";
var tokenExpander = new TokenExpander
    {
        RegEx = new Regex("{{{ @content }}}"), // you can also use Mustache syntax: {{> content }}
        ExpandTokens = (s, baseOptions) => Tokenizer.Tokenize(stringData, baseOptions) // Instead of baseOptions, you can pass a new ParsingOptions object, which has no TokenExpanders to avoid infinite loops.
    };
var parsingOptions = new ParsingOptions { TokenExpanders = new[] { tokenExpander } };
var template = Mustachio.Parser.Parse(sourceTemplate, parsingOptions);

// Create the values for the template model:
dynamic model = new ExpandoObject();
model.testVar = "Test";

// Combine the model with the template to get content:
var content = template(model);

Installing Mustachio:

Mustachio can be installed via NuGet:

Install-Package Mustachio
Key differences between Mustachio and Mustache

Mustachio contains a few modifications to the core Mustache language that are important.

  1. each blocks are recommended for handling arrays of values. (We have a good reason!)
  2. Complex paths are supported, for example {{ this.is.a.valid.path }} and {{ ../this.goes.up.one.level }}
  3. Template partials are supported via Token Expanders.
A little more about the differences:

One awesome feature of Mustachio 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.

More Repositories

1

postmark-templates

Rock-solid transactional email templates for applications.
HTML
2,836
star
2

mailmason

A complete toolset to streamline building and updating a set of consistent transactional emails.
Handlebars
912
star
3

postmark-rails

Official integration library for using Rails and ActionMailer with the Postmark HTTP API
Ruby
340
star
4

postmark.js

Official Node.js library for the Postmark API
TypeScript
294
star
5

postmark-gem

Official Ruby client library for the Postmark HTTP API
Ruby
197
star
6

postmark-php

The official PHP library for Postmark.
PHP
155
star
7

PactMaker

Starter workflow for creating electronically signed PDF agreements.
EJS
132
star
8

activecampaign-api-php

PHP
113
star
9

postmark-cli

The official CLI tool for Postmark
TypeScript
74
star
10

style-merge

Simple CSS inlining, for email.
C#
68
star
11

swiftmailer-postmark

The Official Swiftmailer Transport for Postmark.
PHP
53
star
12

mailhandler

Simple lightweight mail library which allows you to send and retrieve emails, and get more details about email sending and delivery
Ruby
53
star
13

postmark-dotnet

A .NET library for the Postmark API
C#
47
star
14

smtp-field-manual

A collection of raw STMP server responses from major email service providers and spam filter services.
JavaScript
44
star
15

activecampaign-api-nodejs

Node.js wrapper for the ActiveCampaign API
JavaScript
39
star
16

postmark-java

Official Java client library for the Postmark HTTP API
Java
36
star
17

mailbrush

Node.js library for generating email friendly snippets with syntax highlighting
JavaScript
33
star
18

laravel-postmark-provider

A Postmark adapter for Laravel 5+
PHP
30
star
19

postmark_webhooks

Lightweight quickstart app for receiving and processing webhooks from Postmark
JavaScript
29
star
20

postmark-wordpress

The Official Postmark Wordpress Plugin
PHP
19
star
21

postmark-nodemailer

Using Postmark to send transactional emails through nodemailer
JavaScript
17
star
22

postmark-firebase

Postmark + Firebase + Cloud Functions Tutorial
HTML
15
star
23

craft3-donottrack

Craft 3 plugin for respecting Do Not Track headers sent by browsers.
PHP
13
star
24

module-integration

PHP
8
star
25

camp-css

CSS behind the distinctive style of ActiveCampaign
CSS
7
star
26

example-subscription_form_embed

ActiveCampaign Subscription Form API Script: Embed and customize your forms on any site.
PHP
6
star
27

example-sso_embed

Use SSO to link users to ActiveCampaign (bypassing the login), or embed as an iFrame.
PHP
6
star
28

postmark-coldfusion

ColdFusion library for sending emails through Postmark - http://postmarkapp.com
ColdFusion
5
star
29

app-wordpress

The official ActiveCampaign WordPress plugin
PHP
5
star
30

fakemail

Ruby
3
star
31

example-reseller_account_manage

ActiveCampaign Reseller Account Custom API Script: Add account, template, generate log-in link, and more.
PHP
3
star
32

ac-google-sheets-app-scripts

ActiveCampaign apps scripts to add helper functions to google sheets.
3
star
33

example-rest_hooks

Interact and manage ActiveCampaign webhooks via our REST API.
PHP
3
star
34

fakebounce

bounce generating tool
Ruby
3
star
35

example-add_subscriber_send_instant

Add a subscriber and trigger instant responders to send.
PHP
3
star
36

inbound-demo-rails

Demo showing how to use Postmark’s inbound email processing in a Rails app.
Ruby
3
star
37

aws-ssh-helper

Generates SSH configuration from EC2 metadata
PHP
3
star
38

example-recent_campaigns_rss

Recent Campaigns formatted as RSS.
PHP
2
star
39

camp-ui

Camp UI is the main source of Sketch files for our ActiveCampaign product design system.
2
star
40

camp-site

Vue
2
star
41

stylelint-config-activecampaign

Stylelint configuration used by ActiveCampaign
JavaScript
2
star
42

qa-configurator

simple configuration tool
Ruby
2
star
43

php56-apache-browsers-with-extensions

Dockerfile
1
star
44

ac-style-guide

Style Guide for ActiveCampaign
CSS
1
star
45

example-view_contact_details

View a contact's details including list subscriptions, custom field data, recent actions, and campaign history
PHP
1
star
46

ember-route-action-helper

JavaScript
1
star
47

vcard

PHP
1
star
48

craft-customerio

Craft CMS plugin for pushing newsletter subscribers to Customer.io
PHP
1
star
49

grunt-postmark

Send emails through Postmark using GruntJS.
HTML
1
star