Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Handlebars.js | 16,940 | 396,970 | 12,493 | 3 months ago | 83 | February 15, 2021 | 84 | mit | JavaScript | |
Minimal templating on steroids. | ||||||||||
Mustache.js | 15,718 | 40,857 | 4,346 | 2 months ago | 39 | March 28, 2021 | 95 | mit | JavaScript | |
Minimal templating with {{mustaches}} in JavaScript | ||||||||||
Hogan.js | 5,100 | a year ago | 36 | apache-2.0 | JavaScript | |||||
A compiler for the Mustache templating language | ||||||||||
Scriban | 2,367 | 28 | 121 | 9 days ago | 105 | July 11, 2022 | 43 | bsd-2-clause | C# | |
A fast, powerful, safe and lightweight scripting language and engine for .NET | ||||||||||
Web Mode | 1,556 | 11 days ago | 5 | gpl-3.0 | Emacs Lisp | |||||
web template editing mode for emacs | ||||||||||
Dustjs | 1,468 | 11 years ago | 1 | July 08, 2016 | 55 | mit | JavaScript | |||
Asynchronous templates for the browser and node.js | ||||||||||
Grmustache | 1,436 | 203 | 7 years ago | 58 | April 23, 2015 | 12 | mit | Objective-C | ||
Flexible and production-ready Mustache templates for MacOS Cocoa and iOS | ||||||||||
Handlebars.java | 1,364 | 517 | 123 | 23 days ago | 51 | October 12, 2021 | 121 | other | Java | |
Logic-less and semantic Mustache templates with Java | ||||||||||
Mustache | 1,020 | 20 | 20 | 2 years ago | March 18, 2012 | 32 | mit | Go | ||
The mustache template language in Go | ||||||||||
Icanhaz.js | 845 | 6 years ago | 1 | December 14, 2015 | 18 | other | JavaScript | |||
A clean solution for templating with Mustache.js and jQuery or Zepto |
Whisker is a {{Mustache}} implementation in R confirming to the Mustache specification. Mustache is a logicless templating language, meaning that no programming source code can be used in your templates. This may seem very limited, but Mustache is nonetheless powerful and has the advantage of being able to be used unaltered in many programming languages. It makes it very easy to write a web application in R using Mustache templates which could also be re-used for client-side rendering with "Mustache.js".
Mustache (and therefore whisker) takes a simple, but different, approach to
templating compared to most templating engines. Most templating libraries,
such as Sweave
, knitr
and brew
, allow the user to mix programming code and text
throughout the template. This is powerful, but ties your template directly
to a programming language and makes it difficult to seperate programming code from
templating code.
Whisker, on the other hand, takes a Mustache template and uses the variables of the
current environment
(or the supplied list
) to fill in the variables.
The syntax of Mustache templates is described in https://mustache.github.io/mustache.5.html How the mustache template are used with whisker can be found in the whisker documentation, and below.
Whisker conforms to the Mustache 1.1 specificaton except for delimiter switching and lambdas. We expect that these will be implented shortly.
To install whisker use the following statement in your R console
install.packages("whisker")
The latest whisker version is not yet available on CRAN, but can be installed from github:
library(devtools)
# dev_mode()
install_github("whisker", "edwindj")
whisker.render
accepts a character
template and a list or environment containing data to render:
library(whisker)
template <-
'Hello {{name}}
You have just won ${{value}}!
{{#in_ca}}
Well, ${{taxed_value}}, after taxes.
{{/in_ca}}
'
data <- list( name = "Chris"
, value = 10000
, taxed_value = 10000 - (10000 * 0.4)
, in_ca = TRUE
)
text <- whisker.render(template, data)
cat(text)
## Hello Chris
## You have just won $10000!
## Well, $6000, after taxes.
Or using a text file
library(whisker)
template <- readLines("./template.html")
data <- list( name = "Chris"
, value = 10000
, taxed_value = 10000 - (10000 * 0.4)
, in_ca = TRUE
)
writeLines(whisker.render(template, data), "./output.html")
By default whisker
applies html
escaping on the generated text.
To prevent this use {{{variable}}}
(triple) in stead of {{variable}}
.
template <-
"I'm escaped: {{name}}
And I'm not: {{{name}}}"
data <- list( name = '<My Name="Nescio">')
whisker.render(template, data)
Generates:
I'm escaped: <My Name="Nescio">
And I'm not: <My Name="Nescio">