1.0.0 • Published 8 years ago

mandrill-template-helpers v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

Mandrill Template Helpers

Mandrill supports a few helpers that are not included with handlebars: upper, lower, title, url, date, striptags & unsub

This acts as a polyfill for those helpers allowing you to build and test your templates locally before publishing

Installation

npm install mandrill-template-helpers --save

Test

npm test

Usage

In your code

var hb = require('handlebars');
var mandrill-helpers = require('mandrill-template-helpers');

hb.registerHelper(mandrill-helpers);

...

var template = hb.compile('./template.html');

in your ./template.html do

    {{#if shout_out}}
        {{upper shout_out}}!
    {{/if}}

if shout_out was hello then it would return HELLO

Inline Helpers Available in Mandrill

From Mandrill...

HelperFunctionExample
upperuppercase the text provided{{upper "your text"}} results in: YOUR TEXT
lowerlowercase the text provided{{lower "your text"}} results in: your text
titletitle-case the text provided{{title "your text is neat"}} results in: Your Text is Neat
urlurlencode the text provided{{url "http://yourawesomeurl.com"}} results in: http%3A%2F%2Fyourawesomeurl.com
dateprint the current date with a given format, defaults to d/m/Y{{date "Y-m-d"}} results in: 2015-03-10
striptagsstrip any HTML tags from the given data{{striptags "<p>your text</p>"}} results in: your text

Mandrill also offers another helper, {{unsub}} to add an automatic unsubscribe link to your emails. Generally, you would add the unsub helper in handlebars as {{unsub "http://redirecturl.com"}} where you pass the URL directly in the helper and the URL must be enclosed in double quotes. For example:

<a href='{{unsub "http://redirecturl.com"}}'>Unsubscribe</a>

You can also pass the redirect URL as a merge_var:

<a href='{{unsub redirect_merge_var}}'>Unsubscribe</a>

with the merge var defined as:

   "global_merge_vars": [
        {
            "name": "redirect_merge_var",
            "content": "http://yourdomain.com"
        }
    ]

Note: When using the {{unsub}} helper inside of an anchor tag, be sure to use single quotes around for the href='{{unsub }}'.

see: Using-Handlebars-for-Dynamic-Content

Todo

  • implement date helper
  • create placeholder for unsub

LICENCE

MIT