whisker.render: Logicless templating

Description Usage Arguments Value Note Examples

View source: R/whisker.R

Description

Logicless templating

Usage

1
2
whisker.render(template, data = parent.frame(), partials = list(),
  debug = FALSE, strict = TRUE)

Arguments

template

character with template text

data

named list or environment with variables that will be used during rendering

partials

named list with partial templates, will be used during template construction

debug

Used for debugging purposes, likely to disappear

strict

logical if TRUE the seperation symbol is a "." otherwise a "$"

Value

character with rendered template

Note

By default whisker applies html escaping on the generated text. To prevent this use {{{variable}}} (triple) in stead of {{variable}}.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
template <- "Hello {{place}}!"
place <- "World"

whisker.render(template)

# to prevent html escaping use triple {{{}}}
template <- 
  "I'm escaped: {{name}}
And I'm not: {{{name}}}"

data <- list( name = '<My Name="Nescio&">')
whisker.render(template, data)
# I'm escaped: &lt;My Name=&quot;Nescio&amp;&quot;&gt;
# And I'm not: <My Name="Nescio&">

whisker documentation built on Aug. 28, 2019, 9:04 a.m.