LoginSignup
3
3

More than 5 years have passed since last update.

Sailsでページ毎にJSやCSSを読み込む

Posted at

詰まったのでメモ

結論

sailsはejs-localsを使用しているので、これに沿って書けばOK

ejs-locals

layout.ejs

<!DOCTYPE html>
<html>
  <head>
    <title><%= title %></title>
    <!--STYLES-->
    <!--STYLES END-->
    <!--SCRIPTS-->
    <!--SCRIPTS END-->
    <%-scripts%>
    <%-stylesheets%>
  </head>
  <body>
    <%-body -%>
  </body>
</html>

index.ejs

<% script('foo.js') -%>
<% stylesheet('foo.css') -%>

<div class="wraper">
  ほげほげ
</div>

注意点

<!--STYLES-->
<!--STYLES END-->

<!--SCRIPTS-->
<!--SCRIPTS END-->

の間に

<%-scripts%>
<%-stylesheets%>

などを書くと、実行時に書き消されてしまうため注意です。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3