Roy Tsabari
Roy Tsabari

Reputation: 2040

Underscore.js template on Java server

I'm building a single page web app when Backbone.js is my MV* framework. It requires Underscore.js so I wan't to use it as my template engine. I set the template result as the view content to display in it's render function:

this.el.append( compiledTemplate );

I wonder about the right way to implement the template code:

  1. Should it be a JS code that produce an HTML text?
  2. Should it be an HTML file with a script tag to include the JS code?
  3. How can I separate the display from the logic?
  4. How can I write my CSS in a separate file (not in JS file)?

Upvotes: 0

Views: 544

Answers (1)

fguillen
fguillen

Reputation: 38772

  1. Well... this is what the Underscore template engine is, isn't it? so, no, your template should be HTML with interpolate tags.

  2. Normally it is a DOM element whose content is the template, and, yes, it is used to be a script tag.

  3. Force your self to only use interpolate Model attributes in your templates. You can pass especial pre-calculated attributes if you use any kind of Decorator technique.

  4. There is not any Backbone or Underscore restriction to you not include your external CSS files as usual.

Upvotes: 1

Related Questions