Skip to content

documentation of "escaping handlebars expressions" could be improved #2094

@macgyver

Description

@macgyver

in reference to this https://handlebarsjs.com/guide/expressions.html#escaping-handlebars-expressions

first of all, linking directly does not work (at least in Firefox..), so to see what I'm talking about you must do this:

  1. visit this page https://handlebarsjs.com/guide/
  2. on the left side navigation menu, under Language Guide, click Expressions
  3. either scroll all the way down the page, or, in the right side "On this page" menu, click "Escaping Handlebars expres..."

it looks like this

Image

it says this:

Handlebars content may be escaped in one of two ways, inline escapes or raw block helpers. Inline escapes created by prefixing a mustache block with . Raw blocks are created using {{{{ mustache braces.

the documentation text states that quadruple staches are used to create raw blocks, but then the example shows that there is a built-in block helper for raw blocks - it seems the latter is correct, the former does not seem to work. in both cases, it seems like a pretty useless feature.. maybe an example that demonstrates a real-world use case would be good?

I stumbled upon this while trying to use handlebars to render source code for another templating language which also uses brackets to delimit the code blocks (it is "Zephyr" which is a template language for a large newsletter service called Sailthru) - it frustratingly does not support white space between the delimiting brackets and the operands so I had a bit of trouble with getting the brackets sorted out, this "escaping" feature seemed like it would be useful here but ended up not helping me at all.

I needed to escape the final closing brace in this line because handlebars chokes on it - it confuses the three braces at the end for a mismatch of the two braces that opened the expression

{if {{variable_variable_name}}}

but the escape of a single brace does not work either, it renders the back slash

{if {{variable_variable_name}}\}

I ended up doing something like this:

{if {{concat variable_variable_name '}'}}

which is pretty ugly.

I think this would have also worked, not any better

{if {{variable_variable_name~}} }

would have been nice if the brace matching was more tolerant, or escaping a closing brace was possible

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions