Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to serve a bootstrap template in sails 0.9?

I wanted to know how to serve a bootstrap template through newer sails version . Should I update the links of JS to something else . I tried moving js and images in asset folder but javascript didn't work . The sails documentation is very poor on this topic . Can anyone tell a easy way to integrate it . Thanks in advance

like image 887
Bhanu423 Avatar asked Jul 29 '13 16:07

Bhanu423


1 Answers

Sails 0.9.x has moved to use Grunt for handling assets. This allows you to do many different kinds of pre-compilation and asset handling. By default, automatic asset injection into your views and layouts is not available.

We have added a flag you can include when generating a new sails project that will create a folder within your assets folder and automatically inject any files into you index.html or layout file. This should only be used for development.

sails new <project name> --linker

Now you will have a folder titled linker under your assets folder that you can place files in to have them automatically linked. It will also add some tags to your index.html file and your layout file to know where to inject the various JS, CSS and templates.

You can read more here: Sails Wiki - Assets

If you are working with a project that has already been created you can manually create the following file structure:

assets/
  linker/
    js/
    styles/
    templates/

You will also need to add the following tags to your view:

<!--SCRIPTS-->
All .js files in assets/linker/js will be included here
In production mode, they will all be concatenated and minified
<!--SCRIPTS END-->

<!--STYLES-->
All .css files in assets/linker/styles (including automatically compile ones from LESS) will be included here
In production mode, they will all be concatenated and minified
<!--STYLES END-->

<!--TEMPLATES-->
All *.html files will be compiled as JST templates and included here.
<!--TEMPLATES END-->

So to use bootstrap and have the files automatically added to your page you will place the bootstrap.js files into assets/linker/js and the bootstrap.css file into assets/linker/css.

In production you will want to edit the gruntfile to compile all of your css and js into single files and manually link them in your view/layout/index.html.

like image 182
particlebanana Avatar answered Sep 22 '22 14:09

particlebanana