GithubHelp home page GithubHelp logo

Comments (27)

leshill avatar leshill commented on May 28, 2024

Hi @syphoxy,

Check issue #25 for some suggestions. Let me know if you still have trouble.

from handlebars_assets.

syphoxy avatar syphoxy commented on May 28, 2024

I've read that ticket before. it doesn't help me much or I'm not really understanding how to fix it.

from handlebars_assets.

leshill avatar leshill commented on May 28, 2024

Hi @syphoxy,

Do you see the templates in your compiled assets if your run rake assets::precompile?

from handlebars_assets.

syphoxy avatar syphoxy commented on May 28, 2024

upon further investigation into the precompiled application.js I can see the template assets in there but for some reason it's not working. it still says that the function isn't defined.

from handlebars_assets.

leshill avatar leshill commented on May 28, 2024

Hi @syphoxy,

Hmm, is this an ordering problem? In application.js (or whatever your JS asset file is) require handlebars should be pulled in before you pull in the templates?

from handlebars_assets.

leshill avatar leshill commented on May 28, 2024

Hi @johnschult,

Are the templates in the complied application.js? Do you have a gist of your setup that I can run locally to see the problem?

from handlebars_assets.

johnschult avatar johnschult commented on May 28, 2024

+1

Except that it doesn't work at all in development for me.

Gemfile

group :assets do
  gem 'handlebars_assets'
  ...
end

application.rb

if defined?(HandlebarsAssets)
  HandlebarsAssets::Config.template_namespace = 'JST'
end

application.js.coffee

JST['items/item']({foo: "bar"})

app/assets/javascripts/templates/items/item.html.hbs

<div>{{foo}}</div>

from handlebars_assets.

leshill avatar leshill commented on May 28, 2024

Hi @johnschult,

What version of the gem is running?

from handlebars_assets.

johnschult avatar johnschult commented on May 28, 2024
handlebars_assets (0.6.4)

There isn't any conflict when using with the handlebars-rails gem is there?

from handlebars_assets.

johnschult avatar johnschult commented on May 28, 2024

application.js.coffee

#= require handlebars.runtime
#= require_tree ./templates

Also, this is Rails 3.2.8...

from handlebars_assets.

leshill avatar leshill commented on May 28, 2024

Hi @johnschult,

No idea on handlebars-rails, why do you need both? (I would remove it and try that :)

And one thing I am seeing, which is currently not tested in any way by me is that your application.js is CoffeeScript.

CoffeeScript wraps everything inside an anonymous scope, so it is possible that HandlebarsTemplates are in there :(

Would you try a pure JS application.js and report back?

from handlebars_assets.

johnschult avatar johnschult commented on May 28, 2024

I tested with and without handlebars-rails. It makes no difference. I was under the impression that handlebars_assets and handlebars-rails were mutually exclusive as far as functionality? I was using handlebars-rails so that I could use the templates in Ruby and JS.

Changing to use application.js would be a major undertaking for me. I have quite a bit of stuff in CoffeeScript and I am not really looking to stop using it.

from handlebars_assets.

johnschult avatar johnschult commented on May 28, 2024

If it was getting wrapped under the anonymous scope, Handlebars would not be available in the JS console, but it is. Correct?

from handlebars_assets.

leshill avatar leshill commented on May 28, 2024

Hi @johnschult,

Yes.

Are the templates in the compiled application.js? Turning off config.assets.compress will make it easier to see.

from handlebars_assets.

johnschult avatar johnschult commented on May 28, 2024

application.js (after compilation)

$(function() {
    var $container, $errorInput, $pagination, resetUrlEntry;
    JST['items/item']({
      foo: "bar"
    });
    ...

Which brings me to the problem in the browser:

Uncaught ReferenceError: JST is not defined 

That's the only thing I can see related to the template. I assume there is supposed to be more?

from handlebars_assets.

johnschult avatar johnschult commented on May 28, 2024

This looks pretty suspicious.... right at the end of application.js.

Handlebars.template = Handlebars.VM.template;
;
(function() {



}).call(this);

from handlebars_assets.

leshill avatar leshill commented on May 28, 2024

Hi @johnschult,

If everything is setup correctly, inside of application.js you should see this line:

this.JST['items/item'] = Handlebars.template(...

because you are using the JST namespace.

Debugging via github issues is a pain :(

from handlebars_assets.

johnschult avatar johnschult commented on May 28, 2024

Clearly I have something wrong, or more likely CoffeeScript is messing with me. I am happy to work with you on this further if you care, but I am losgin interest quickly ;-) I only need this for one small template right n ow, and it gets used a lot on the inde page so I wanted to make sure it was precompiled. I can just do that myself for now.

Sorry to drop off, but I need to get some work done tonight :-0 Thanks for your many replies man!

from handlebars_assets.

leshill avatar leshill commented on May 28, 2024

Hi @johnschult,

No worries! Good luck.

from handlebars_assets.

syphoxy avatar syphoxy commented on May 28, 2024

Thank you, @leshill. we ended up figuring out the problem that day.

the javascript assets were being loaded in the wrong order due to a //= require_directory . directive so the templates were coming in after the javascript that used them.

from handlebars_assets.

leshill avatar leshill commented on May 28, 2024

Hi @syphoxy,

Awesome! Good to know.

from handlebars_assets.

brooksjbr avatar brooksjbr commented on May 28, 2024

Hi leshill,

I'm running into a similar issue. I'm getting the same 'Uncaught ReferenceError: HandlebarsTemplates is not defined' when trying to reference my hbs template. This is in dev and I'm not using coffeescript.

My application.js looks like this.
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require mustache
//= handlebars.runtime.js
//= require_tree ./templates
//= require_tree .

When I view source I can see handlebars.js was loaded, not sure what I'm missing. Any ideas?

from handlebars_assets.

leshill avatar leshill commented on May 28, 2024

Hi @brooksjbr,

Do you see the HandlebarsTemplates global in the JS inspector? Do you see the templates when you view source?

from handlebars_assets.

brooksjbr avatar brooksjbr commented on May 28, 2024

Hey @leshill,

Thanks for the quick response. I don't see HandlebarsTemplates in the js console.

from handlebars_assets.

leshill avatar leshill commented on May 28, 2024

Hi @brooksjbr,

How about when you view source?

from handlebars_assets.

brooksjbr avatar brooksjbr commented on May 28, 2024

Hey @leshill,

I was able to figure out the issue. Another thing I encountered was my template index.js was getting loaded before handlebars.js which threw an error. I ended up moving //= require_tree ./templates to the bottom of my js manifest to resolve it. Is there's a preferred method to deal with load order in a case like that?

Also, I'm a little fuzzy about the index.js. Is this compiled per request or cached somewhere? I assume when assets are precompiled all the templates are added to the application.js. Is that correct?

Thanks for your help and creating the gem.

from handlebars_assets.

leshill avatar leshill commented on May 28, 2024

Hi @brooksjbr,

Unfortunately no, the load system in the asset pipeline is very simple.

Not sure what the question about index.js is, but just to be clear, you should be naming your handlebars templates something like index.hbs.

By default, in development, the files will watched and reloaded when changed (with some caveats). And yes, when precompiling all the required assets are pulled into the application.js file.

from handlebars_assets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.