Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to include js files in Handlebars template #1539

Closed
oieesah opened this issue Mar 28, 2014 · 5 comments
Closed

How to include js files in Handlebars template #1539

oieesah opened this issue Mar 28, 2014 · 5 comments
Labels
support Questions, discussions, and general support

Comments

@oieesah
Copy link

oieesah commented Mar 28, 2014

I am using hapi.js as server side framework with handlebars as template engine. I tried including a js (jquery or custom functions) file in simple html page. But 404 message prompting in browser console. I don't really know whether its hapi.js or handlebars issue. Looking for expert advice! Thanks for any help!

@hueniverse
Copy link
Contributor

Can't really help much with these details. Can you post some code showing what you are trying to do or a link to your project?

@oieesah
Copy link
Author

oieesah commented Mar 30, 2014

I have found the issue. I was actually unable to serve js file in a html file (included but 404) which i was rendering through handlebars. So i made a route for the static folder and now that html file can access the js file.

But i would like to have your advise on how i should serve css, images, and js file (custom written) in my html pages.

Thanks.

I'm a newbie so i was continuously thinking about whether i should create an issue or not. Because my question was a total noob.

I am doing my best to adopt it and learn it as fast as i can. So i can recommend it to others. I know a little about the efforts you guys putting in it to make it The Best framework.
Good Luck!

@jameswyse
Copy link

You can serve static files like so:

app.js:

server.route({
  method: 'GET',
  path: '/{filename*}',
  handler: {
    directory: {
      path:    __dirname + '/public',
      listing: false,
      index:   false
    }
  }
});

server.route({
  method: 'GET',
  path: '/',
  handler: function(request, reply) {
    reply.view('homepage');
  }
});

Then any files in the public directory will be available, eg public/js/jquery.min.js could be included with <script src="/js/jquery.min.js"></script>

Check out issue #1489 for some getting started guides :)

@projenix
Copy link

Thank you James, this seems to unfortunately be nowhere in the official documentation or tutorials.

@arb
Copy link
Contributor

arb commented Apr 16, 2015

@hapijs hapijs deleted a comment from shubhamkoolwal Sep 14, 2017
@hapijs hapijs locked and limited conversation to collaborators Sep 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

5 participants