Closed PhoebeJacinda closed 1 year ago
Hi @PhoebeJacinda - yes, this is achievable in jinjar. Your goal is to compare a variable to a string literal within your template. You've encountered difficulty around escaping your string literal.
x == "yes"
compares variable x
to the string yes
.x == "\"yes\""
compares variable x
to the string "yes"
.x == "\\"yes\\""
compares variable x
to the string "yes"
. If you are rendering a template defined in a text file, then this additional escaping is not required.In summary, here's some example code showing how to make your desired string comparison.
library(jinjar)
template <- '{% if x == "\\"/ *\\"" -%}Hello world{% endif %}'
render(template, x = "nope")
#> [1] ""
render(template, x = '"/ *"')
#> [1] "Hello world"
Created on 2023-02-06 with reprex v2.0.2
Leaving ticket open to remind me to add this question to the docs.
I would like to check if a value is equal to this string -> "/ " and the quotation mark is a part of the value. I tried to run {% if x != '"/ "' %} but the rendering did not work. Is there any way to work around it so I can completely render the quotation mark?