Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handlebars templates using ampersand and caret

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";
like image 403
BishopZ Avatar asked Nov 19 '14 20:11

BishopZ


People also ask

How do you add templates in your HTML in Handlebars?

Templates The recommended way of adding templates to your page is by including them in <script> tags with a special type. The type attribute is important, otherwise the browser will attempt to parse them as JavaScript (which they are not). The templates have an easy to grasp syntax.

What is Handlebars template in Ember?

Ember uses the Handlebars templating library to power your app's user interface. Handlebars templates contain static HTML and dynamic content inside Handlebars expressions, which are invoked with double curly braces: {{}} . Dynamic content inside a Handlebars expression is rendered with data-binding.

Is Handlebars a template language?

Handlebars is a simple templating language. It uses a template and an input object to generate HTML or other text formats. Handlebars templates look like regular text with embedded Handlebars expressions. A handlebars expression is a {{ , some contents, followed by a }} .

How do I compile Handlebars templates?

Precompiling Templates Inside NodeJS If you wish to precompile templates from inside NodeJS--without invoking "handlebars" from the command line--that can be done with Handlebars. precompile. Transmit the string result of this function to your clients, and they can in turn parse that with Handlebars. template.


1 Answers

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}}}
like image 188
lossleader Avatar answered Oct 19 '22 10:10

lossleader