leshill / handlebars_assets

Use handlebars.js templates with the Rails asset pipeline.
MIT License
649 stars 159 forks source link

Not an error but still nothing in view #156

Closed ijunaid8989 closed 7 years ago

ijunaid8989 commented 7 years ago

I am working in handlebars withing backbone alongside with Rails.

My application.js file looks like

//= require jquery
//= require handlebars.runtime
//= require ./lib/underscore
//= require ./lib/backbone
//= require ./app/rabone

my main app file

#= 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 this is my view file

class App.Views.Header extends Backbone.View

  template: HandlebarsTemplates['app/templates/header.hbs']

  render: ->
    @$el.html(@template)
    @

That's not giving me any kind of error but also not showing anything in my browsers as well. But if do this @$el.html(@template())

then I got some erorrs as Uncaught TypeError: this.template is not a function

AlexRiedler commented 7 years ago

If you do HandlebarsTemplates in a javascript console on the page; what is the result.

I think its 'app/templates/header' without the extension (although I could be wrong)

or even more particular; what is this.template? if its not a function.

ijunaid8989 commented 7 years ago

image

But the thing is template is a method in view which is not available in render

ijunaid8989 commented 7 years ago

this worked template: HandlebarsTemplates['header']