Reputation: 2608
I am working in Rails with BackboneJS in handlebar templates.
I am getting a weird error here.. this is my header view
class App.Views.Header extends Backbone.View
className: "navbar-inner"
template: HandlebarsTemplates['app/templates/header']
render: ->
@$el.html(@template())
@
main application file is this
#= require_self
#= require_tree ./templates
#= require_tree ./views
#= require_tree ./routers
window.App =
Routers: {}
Views: {}
Collections: {}
Models: {}
initialize: ->
new App.Routers.MainRouter()
Backbone.history.start()
and my main router file is this
class App.Routers.MainRouter extends Backbone.Router
routes:
"": "index"
initialize: ->
@headerView = new App.Views.Header()
index: ->
$("#header").html(@headerView.render().el)
when I hit localhost:3000
.. I got this error upfront.
Uncaught TypeError: this.template is not a function
..
Am totally stuck in that any help will be appreciated Thanks
Upvotes: 1
Views: 1785
Reputation: 2608
template: HandlebarsTemplates['header']
Template path should be only the template itself.
May that is version due to version or assets precompiled
Upvotes: 1
Reputation: 2293
It sounds like the Handlebars template in HandlebarsTemplates['app/templates/header']
either does not exist, has not been compiled, or there may have been an error while compiling it. That's the error you'd get if that value was null or undefined.
You might want to try setting a breakpoint in your browser's javascript debugger in the call to render
, then use the debugger to check the value of this.template
and see what's going on.
Upvotes: 0