whisker icon indicating copy to clipboard operation
whisker copied to clipboard

impossible to use named sections when key is unknown

Open bjoernhommel opened this issue 5 years ago • 0 comments

Thanks for a great package. R really needs a good templating engine.

If the names of hash$people are unknown, there appears to be now way of accessing the data in it's children.

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))

Link to stackoverflow.

bjoernhommel avatar Dec 02 '19 19:12 bjoernhommel