Search code examples
javascriptbackbone.jsrequirejsmarionetteeco

ECO templates with Backbone + Marionette but without Rails


I am trying to use ECO templates with Backbone and Marionette but without Rails. Rather, I am using Django with RequireJS managing my front-end asset pipeline.

How do I load ECO templates?

Here is what a simple Marionette view looks like for me using Underscore's templates:

define ['cs!app', 'requirejs-tpl!./templates/message.tpl'], (App, message) ->
  App.module 'About.Show', (Module, App, Backbone, Marionette, $, _) ->
    class Module.MessageView extends Marionette.ItemView
      className:  'message-view'
      tagName:    'div'
      template:   message

I'm guessing I need to set the template key to a ECO template file and then override the view's render method -- but I am not sure as I believe I must precompile the ECO file first...

Things I am going to try:


Solution

  • The short answer here is to install eco via npm and then run something like eco -i JST form.eco. Then, you assign JST['form'] to the view's template attribute. Setting this up manually for multiple templates is probably a bid job, so it is probably best to look at something like django-pipeline.