JavaScript Template Syntax – Double-Brackets Usage

javascript

I'm looking at the source code for a Rails application that uses Backbone and there are template files with .jst.ejs extensions.

The templates include HTML with lines of JavaScript wrapped in double-square-brackets like this this example:

[[ if (currentUser) { ]]
  <h1>Welcome, back!</h1>
[[ } else { ]]
  <h1>Please sign up!</h1>
[[ } ]]

What is the name of this template syntax?

Best Answer

I'm not sure if many template syntaxes have a specific name. A lot of template syntaxes are unique, but there are frameworks out there that use similar templating syntaxes without actually calling them anything. Mostly, they are referred to by the name of the engine.

For example, both Twig (a templating engine that can be used with the Symfony Framework for PHP) and AngularJS (a javascript Framework) have ways of binding by means of the {{ }} syntax. A code sample could be said to be using a Twig-like or Angular-like syntax, but as far as I know there are very few templating syntaxes out there that are standardized and implemented in different engines and can therefore be 'named'.

Related Topic