Search code examples
javascriptbackbone.js

Is there any method to integrate velocity template with backbone.js?


I have a website which was wrote by java. The template is velocity,rendering by javacode. Now i wanna to write some code by backbone.js, but when i using backbone,the template (underscore.js) is not compatible with velocity syntax.

How can I use velocity template with backbone.js?


Solution

  • if it is an issue with the current interpolaters (not sure if that is a word but I mean the <% and %>) in underscore you can change these as per the docs say (http://underscorejs.org/#template)

    If ERB-style delimiters aren't your cup of tea, you can change Underscore's template settings to use different symbols to set off interpolated code. Define an interpolate regex to match expressions that should be interpolated verbatim, an escape regex to match expressions that should be inserted after being HTML-escaped, and an evaluate regex to match expressions that should be evaluated without insertion into the resulting string. You may define or omit any combination of the three. For example, to perform Mustache.js-style templating:

    _.templateSettings = {
      interpolate: /\{\{(.+?)\}\}/g
    };
    
    var template = _.template("Hello {{ name }}!");
    template({name: "Mustache"});
    => "Hello Mustache!"
    

    if it's not this and i have the wrong end of the stick, say, and ill remove this answer