Template rendering in backbone view

24 Views Asked by At

I am using backbone as a front end in rails 7 application. In view file I am not able to load template as a path.

rails view file code is

- content_for :javascript do
  - javascript_include_tag 'backbone/views/test/test_view'
#estimate-repair
%script{type: 'text/template', id: 'temp-fview'}
  .container

backbone view file code is
backbone/views/test/test_view

var FirstView = Backbone.View.extend({
  el: '#estimate-repair',
  template:_.template($("#temp-fview").html()),

  initialize: function(options){
    options = options || {}
    this.render()
  },
  
  render: function(){
    this.$el.html(this.template());
  }
});

If I use this way to render template code then it is working. It will replace #estimate-repair with code written in script. But I want to use separate template file inside of backbone folder. And write my UI code in that template file instead of rails view file, So that I can reuse this template.

backbone/templates/test/test.jst.hamljs

%script{type: 'text/template', id: 'temp-fview'}
  .container
    .modal.fade#cutomer-confirmation{style: "height:150px;"}

and want to call this template from view file.

template: JST['backbone/templates/test/test'],

but this showing me error in console.
Uncaught ReferenceError: JST is not defined.

Please help me to solve this.

0

There are 0 best solutions below