Search code examples
sails.jsassetsglobal

How in Sails to access globals in assets?


I am using Sails JS and would like to access globals (sails.config.myGlobals) in my assets, currently in js files.

I would have hoped I there is a similar way like injecting in ejs files. But its not.

Any ideas? Do I have to do a Grunt task for that?


Solution

  • I don't think this is possible with Sails.

    However, what you can do is setting the variable in a ejs view file to access its value in your js asset file.

    // someView.ejs
    <script>
        myGlobals = '<%= config.myGlobals %>';
    </script>