Handlebars templates using ampersand and caret

2019-04-26 16:55发布

问题:

We found some old Handlebars templates which are working fine, but include some odd usage of Handlebars.

The two strange ones are

{{^is_question}}{{/is_question}}

and

{{& answer}}

Neither of those are listed in the Handlerbars docs and there are no helpers defined.

Anyone know what they do?

The ^is_question appears to be used interchangeably with {{#if is_question}}. Maybe it is some deprecated shorthand notation?

The template is compiled the same way we compile other templates:

template = Handlebars.compile(ItemTemplate)

Our handlebars version is:

Handlebars.VERSION = "1.0.0-rc.3";

回答1:

I've used ^ relatively recently, but I had to look up &:

{{^ question}} X {{/question}} => inverse selection, i.e. if (! question ) X;
{{& answer}} => unescaped, typically: {{{answer}}}