New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

requirejs-underscore-tpl

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

requirejs-underscore-tpl

RequireJS underscore-tpl, Loads and precompile underscore templates

0.2.0
latest
Source
npm
Version published
Weekly downloads
13
-18.75%
Maintainers
1
Weekly downloads
 
Created
Source

underscore-tpl

underscore-tpl is a RequireJS plugin to load and precompile Underscore.js templates.

Here are some performance tests that show the difference when rendering precompiled templates.

New features in 0.2.0

  • Catch and print template compilation errors. Tip: Use http://rowno.github.io/architect/ for pin point your error.

Usage

Use the tpl! prefix when loading a template.

myview.js

define(['tpl!mytemplate.tpl'], function (template) {

  var MyView = Backbone.View.extend({
    template: template // just pass in the template
  });                  // do not use _.template(), at this point it is already compiled

  return MyView;
});

The plugin will compile the template after requirejs r.js optimizer.

And also when developing, it will compile the template the first time is loaded so that the next time is required it will just render the template saving a function call to underscore's internal render method.

Configuration

You can pass underscoreTemplateSettings to RequireJS config

requirejs.config({
  config: {
    underscoreTemplateSettings: {
      interpolate: /\{\{\s*([^#\{]+?)\s*\}\}/g,  // {{ title }}
      evaluate:    /\{\{#([\s\S]+?)\}\}/g,       // {{# console.log("stuff") }}
      escape:      /\{\{\{([\s\S]+?)\}\}\}/g     // {{{ title }}}
    }
  });

Dependecies

For this plugin to work you need:

License

See LICENSE

Keywords

requirejs

FAQs

Package last updated on 02 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts