Using sails.js as a framework for a node.js app I'm building.
I'm trying to retrieve information previously set by a user (i.e. settings for my app) from the back end, and then use these settings in my client-side javascript.
I currently have a controller which retrieves the information from the database and passes it to the view where it will be needed.
return res.view('dashboard', { configs: configurations });
I know it is accessible when rendering html, but don't know how to pass it to the javascript environment running on the browser.
Any tips would be amazing!
To clarify, I'm not trying to render this information in the html page (i.e. the method of using <%= variable %>
, I want to use it in the javascript running on the page.
If i understood your question correctly; you can use the server side variable in your script tag.
<script>
var something = <%= serversideVariable %>;
var <%= serversideVariable %> = "some value";
</script>
This would work as javascript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With