edwindj / whisker

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

Variables that start with period are replaced with empty string #34

Open seth127 opened 3 years ago

seth127 commented 3 years ago

I was using the pattern sometimes used in the tidyverse where you name your variables something short with a period at the beginning like .v1 or .v2. This doesn't work in whisker for some reason. The variable just gets replaced by an empty string.

See your example (slightly altered) below. When I change name to .name it no longer renders:

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 
## You have just won $10000!
## Well, $6000, after taxes.