• Stars
    star
    274
  • Rank 149,455 (Top 3 %)
  • Language
    JavaScript
  • License
    Do What The F*ck ...
  • Created over 12 years ago
  • Updated over 3 years ago

Reviews

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

Repository Details

A small collection of useful helpers for Handlebars.js

Handlebars Helpers

A small collection of useful helpers for Handlebars.js.

Build Status

This version includes a (very) large API change. Use version 1.1.0 if you'd prefer the "classic" style.

To use, just include helpers.js after you include Handlebars. Or, if you're using AMD/Node, just require the file.

Provided Helpers

The old if_eq, if_gt, unless_gte etc. helpers are now replaced with a much cleaner is helper.

Comparisons

Given one argument, is acts exactly like if:

{{#is x}} ... {{else}} ... {{/is}}

Given two arguments, is compares the two are equal (a non-strict, == comparison, so 5 == '5' is true)

{{#is x y}} ... {{else}} ... {{/is}}

Given three arguments, the second argument becomes the comparator.

{{#is x "not" y}} ... {{else}} ... {{/is}}
{{#is 5 ">=" 2}} ... {{else}} ... {{/is}}

Several comparators are built-in:

  • == (same as not providing a comparator)
  • !=
  • not (alias for !=)
  • ===
  • !==
  • >
  • >=
  • <
  • <=
  • in (check a value exists in either a comma-separated string, or an array, see below)
// Loose equality checking
{{#is x y}} ... {{else}} ... {{/is}}
{{#is x "==" y}} ... {{else}} ... {{/is}}

{{#is x "!=" y}} ... {{else}} ... {{/is}}
{{#is x "not" y}} ... {{else}} ... {{/is}}

// Strict equality checking
{{#is x "===" y}} ... {{else}} ... {{/is}}
{{#is x "!==" y}} ... {{else}} ... {{/is}}

// Greater/Less Than
{{#is x ">" y}} ... {{else}} ... {{/is}}
{{#is x ">=" y}} ... {{else}} ... {{/is}}

{{#is x "<" y}} ... {{else}} ... {{/is}}
{{#is x "<=" y}} ... {{else}} ... {{/is}}

// In comma separated list, or array
{{#is x "in" "foo,bar"}} ... {{else}} ... {{/is}}
{{#is x "in" anArray}} ... {{else}} ... {{/is}}

Registering Custom is comparators

You can extend the provided comparators by registering your own, like so:

// in browser
HandlebarsHelpersRegistry.add('same', function (left, right) { return left === right; });

// with AMD/Node
var HandlebarsHelpersRegistry = require('path/to/helpers');
HandlebarsHelpersRegistry.add('same', function (left, right) { return left === right; });

// usage
var template = '{{#is x "same" y}} Are the same {{else}} Not the same {{/is}}';
Handlebars.compile(template)({ x: 5, y: '5' }); // => " Not the same "

Logging

Log one or multiple values to the console:

{{log foo bar}}

Log one or multiple values to the console, with the current context:

{{debug foo bar}}

nl2br

Convert new lines (\r\n, \n\r, \r, \n) to line breaks

{{nl2br description}}

More Repositories

1

hmac-examples

SHA256 HMAC in different languages (both hex & base64 encoding)
287
star
2

Singing-with-Sinatra

Project files for a Nettuts+ series on Sinatra
CSS
68
star
3

JustDeleteMe-iOS

iOS App for JustDeleteMe (written in Swift)
Swift
48
star
4

avatar-uploader

The image/avatar uploader you always dreamed of
JavaScript
42
star
5

backbone.viewmanager

JavaScript
38
star
6

TutsPlus-Downloader

Download all videos in a Tuts+ Course with one click
JavaScript
18
star
7

JSONx

JSONx is an IBM standard for representing JSON as XML
PHP
18
star
8

JSONx-for-Laravel

Add XML support to your JSON API with a single middleware
PHP
17
star
9

tutsplusmarkdown

Convert your GitHub Flavoured Markdown to HTML for the Tuts+ Network
Ruby
13
star
10

fuel-s3

FuelPHP package for Amazon S3
PHP
13
star
11

GTAV

GTA V Map
JavaScript
12
star
12

fuelbackbonepusher

Demo of FuelPHP, Backbone.js and Pusher
PHP
12
star
13

fuel-exposable-model

FuelPHP package to ease in exposing model properties on your API
PHP
12
star
14

ng-contacts-app

A small "for-fun" AngularJS app, written with a bunch of nice ES6 goodness
JavaScript
10
star
15

portsdegree

University of Portsmouth Degree Classification Calculator
JavaScript
7
star
16

dotfiles

There's no place like home.
Vim Script
7
star
17

InboxActions

Inbox actions for Gmail and any other compatible email client
PHP
7
star
18

Recall

A Nettuts+ project
Ruby
5
star
19

A-Look-at-Popcorn

A quick demonstration of Popcorn for Nettuts+
JavaScript
5
star
20

markdown.js-demo

JavaScript
5
star
21

fuel-cheddar

FuelPHP package for the CheddarGetter API
PHP
4
star
22

playing-with-react-and-redux

JavaScript
4
star
23

Landing-Page

My website during the second half of 2010
4
star
24

babel-repl

REPL with Plugins. Lots to do.
JavaScript
4
star
25

StatusBoard

GitHub powered status reports
JavaScript
4
star
26

speech

Playing with Speech Recognition in WebKit
JavaScript
4
star
27

wordpress-status-checker

A ruby script for checking the status of your WordPress sites
3
star
28

Tagme

Tags. All fancy-like.
JavaScript
3
star
29

fuel-zipencoding

A FuelPHP port of the CodeIgniter Zip Encoding class.
PHP
3
star
30

Jumplist

A bookmarking script for the Bash Shell.
3
star
31

danharper.me-2011-nanoc

My new web site for 2011. Running on the nanoc static-site generator. HTML5 & CSS3 goodness baked right in!
Ruby
2
star
32

Backbone-CSS3-Generator

Demo application
JavaScript
2
star
33

Vim

Mostly for my vimrc file
1
star
34

DTI

Parse ISO 8601 date, duration and interval strings into DateTime objects
PHP
1
star
35

mdedit

Plan is to create a localStorage-backed Markdown editor
JavaScript
1
star
36

ENTWA-Coursework

2013 Enterprise Web Applications Coursework (97.5%)
Java
1
star
37

VoiceJammer

JavaScript
1
star
38

webcam-pip

open webcam in PiP (useful for using Camo when screen recording; Quicktime's preview window doesn't work with Camo)
HTML
1
star
39

dh-clean

Possible new site design
JavaScript
1
star
40

fluxible-decorators-experiment

JavaScript
1
star
41

Mote

On a Mote of Dust
1
star
42

graphql-typescript-codegen

Generate GraphQL from your existing TypeScript codebase
TypeScript
1
star
43

dh2012

Slick new site for 2012 full of CSS3 animations
JavaScript
1
star
44

Stem

A simple fixtures library for PHP
PHP
1
star
45

fuel-pdfcrowd

FuelPHP package for the PDFCrowd API
PHP
1
star
46

AUFDW

JavaScript
1
star
47

bug-removing-NSWindowStyleMaskTitled

remove the NSWindowStyleMaskTitled after creation, and it no longer hit tests properly after resize...
Objective-C
1
star
48

vivaWP.com

Homepage for the upcoming vivaWP open-source WordPress framework
1
star