Skip to content

Instantly share code, notes, and snippets.

@z2015
Created June 27, 2016 10:04
Show Gist options
  • Save z2015/31b229a856b58dd809bac354f32f494e to your computer and use it in GitHub Desktop.
Save z2015/31b229a856b58dd809bac354f32f494e to your computer and use it in GitHub Desktop.
Sails.js - How to inject a js file to a specific route?
<%- blocks.localScripts %>
<% block('localScripts', '<script src="https://maps.googleapis.com/maps/api/js"></script>') %>
// you can add as many as you like
res.locals.scripts = [
'//maps.googleapis.com/maps/api/js',
];
return res.view();
<!--SCRIPTS-->
<!--SCRIPTS END-->
<!-- Loop through all scripts that passed from controller -->
<% if (scripts) { %>
<% for (i = 0; i < scripts.length; i++) { %>
<script src="<%- scripts[i] %>"></script>
<% } %>
<% } %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment