Tuesday, 9 May 2017

How to add another javascript to the page within a template that uses a layout?

I have a NodeJS project that was generated using express generator.

My app.js uses the hbs package:

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');

Being new to handlebars I am confused by the examples that I find that use the handlebars package instead of hbs and would like to know what is the best practice around accomplishing the following in the scenario below:

  • I have layout.hbs that includes jQuery files:

    ... html and body opening }

    ... body and html tags closing

  • In my editor.hbs file, which pretty much is the body portion of the layout.hbs, I would like to add the wysiwyg.js which needs to be after jQuery. When I add it in editor.hbs the script comes before the jQuery and things don't work.

I can't seem to find if there's a best practice of adding sections or blocks or something that would solve this problem. Can you please help steer me in the right direction?

I'm looking for a solution that I can somehow tell layout.hbs that there's an additional javascript that needs to be added from editor.hbs. I'm not looking to add an array of scripts to each router in order to define the scripts.



via Logan

No comments:

Post a Comment