title: Backbone.js with Eco Templates: How to include template within a template?
body: <p>Is it possible to include a template within a template? Maybe something similar to the way ERB handles partials?</p>
  
  <p>Rather than attempting to render nested models in a fashion like ERB, it's better to let Backbone.js take care of this.</p>
  
  <p>Note, I am using coffeescript syntax:</p>
  
  <p>Projects.IndexView</p>
  
  <pre><code>template: JST["backbone/templates/projects/index"]
  
  addAll: () -&gt;
      @options.projects.each(@addOne)
  
  addOne: (project) -&gt;
      view = new Worktimer.Views.Projects.ProjectView({model : project})
      @$("#projects-table").append(view.render().el)
  
  render: -&gt;
      $(@el).html(@template(projects: @options.projects.toJSON() ))
      @addAll()
  </code></pre>
  
  <p>the model Project has a nested collection called sessions:</p>
  
  <p>Projects.ProjectView</p>
  
  <pre><code>template: JST["backbone/templates/projects/project"]
  
  $(@el).html(@template(@model.toJSON() ))     
  for s in @model.sessions.models
      v = new Worktimer.Views.ProjectSessions.ShowView(model: s)
      $(@el).find('.sessions').append(v.render().el)
  </code></pre>
  
  <p>ProjectSessions.ShowView</p>
  
  <pre><code>template: JST["backbone/templates/project_sessions/show"]
  
  render: -&gt;
      $(this.el).html(@template(@model.toJSON() ))
  </code></pre>
  
  <p>so, in the end we have nested templates like this:</p>
  
  <ul>
  <li>Projects Index
  <ul>
  <li>Project
  <ul>
  <li>Session</li>
  <li>Session</li>
  <li>Session</li>
  <li>Session</li>
  </ul></li>
  <li>Project
  <ul>
  <li>Session</li>
  </ul></li>
  <li>Project
  <ul>
  <li>Session</li>
  <li>Session</li>
  </ul></li>
  </ul></li>
  </ul>