I'm trying to use Whisker for HTML-templating in R, but seem to run into problems that should be an easy task for the package. All I want to do is to use sections to loop over a list, with the only problem that I cannot know and therefore specify the names of its elements:
library(whisker)
hash <- list(
people = list(
a = list(
first = "john",
last = "johnsson"
),
b = list(
first = "peter",
last = "petersson"
),
c = list(
first = "steve",
last = "stevesson"
)
),
stuff = c(1:5)
)
template <- "
{{#people}}
<h1>Hello {{first}}</h1>
{{/people}}
"
result <- whisker::whisker.render(template = template, data = hash)
print(HTML(result))
Expected output:
<h1>Hello john</h1>
<h1>Hello peter</h1>
<h1>Hello steve</h1>
I tried using {{#.}}
and .
in all possible constellations, but no luck. This should be a basic requirement of a templating package and I refuse to believe that it isn't possible :S
Any good alternatives to whisker in that case? Thanks