edwindj / whisker

{{mustache}} for R
https://mustache.github.io
213 stars 19 forks source link

templates don't recognise names containing `.` #4

Closed mnel closed 11 years ago

mnel commented 11 years ago

Templates don' t handle names containing .

a.test <- 'World'
template <- template <- "Hello {{a.test}}!"
whisker.render(template)
## Error in value[[key]] : subscript out of bounds
whisker.render(template, list(a.test = a.test))
## [1] "Hello !"
edwindj commented 11 years ago

Thanks for reporting, but it is a difficult one:

It is a kind of conflict between R and mustache/whisker. In the mustache definition, which whisker adheres to a "." signifies a nested object (while in R a ".' is just a character of a variable name).

So strictly speaking your template usage does not conform to the mustache definition.

Whisker currently sticks to the mustache definition

a <- list(test= "Mustache World")  # ( == a$test)
a.test <-  "R World"

template <- "Hello {{a.test}}!"
whisker.render(template)

You can fix your rendering by either changing your template or by changing the list:

a.test <- "World"
template <- "Hello {{a.test}}!"
whisker.render(template, list(a = list(test=a.test)))