Sails does not insert files into assets folder
I just did a fresh set of sails (v0.11.0) on my server and after checking this and working on the controllers I found that the css, js and templates files included in the resource folders are not injected into the layout, if any What are the reasons for this? I mean, this is a clean fresh set of sails ....
source to share
In my quest to get SailsJS to automatically inject the stylesheets into the layout file under the views /layouts/layout.handlebars in my case, I found a couple of things ...
When you first build your sail app using:
sails new APPNAME --template=handlebars --verbose
Note: the link below explains the syntax above ...
Using grip templates in Sails.js
-
Go to config> views.js It will say:
layout: 'layouts/layout.handlebars'
change to:
layout: 'layouts/layout',
-
Go to Tasks> config> sails-linker.js Since I'm in development mode right now, I'll be looking for Ctrl + f: "DevStyles"
devStyles: { options: { startTag: '<!--STYLES-->', endTag: '<!--STYLES END-->', fileTmpl: '<link rel="stylesheet" href="%s">', appRoot: '.tmp/public' }, files: { '.tmp/public/**/*.html': require('../pipeline').cssFilesToInject, 'views/**/*.html': require('../pipeline').cssFilesToInject, 'views/**/*.ejs': require('../pipeline').cssFilesToInject //ADD HANDLEBARS INJECTION HERE } },
Note that .html and .ejs types are inserted into it, but not .handlebars
add this line:
'views/**/*.handlebars': require('../pipeline').cssFilesToInject
where I commented:
//ADD HANDLEBARS INJECTION HERE
At this point you should be able to drop the .css file in properties> styles and copy it to .tmp / public / styles
mileage:
sails lift
on the command line and give it about 20 seconds or so for the stylesheet to display its style on whatever page you have in your routes. js
'/': {
view: 'index'
}
As you can see, I created a new .handlebars file index.handlebars and set it as my root level page. You may need to refresh the page in a time or two to display the newly loaded CSS.
PS It looks like there is no need to add the --linker
first time you create a SailsJS project. Also fyi, I am using sails version 0.11.0
Also if you run sails lift --verbose
, the line below is how you know the .handlebars injection works
verbose: Grunt :: File "views/layouts/layout.handlebars" updated.
Hope this helps!
Also, when adding Handlebars helpers, they should go into a file helper.js
which should be in config> helper.js
At the top of the file, helper.js
I found that I needed to have rudders as shown below.
handlebars = require('sails/node_modules/express-handlebars/node_modules/handlebars');
source to share