Alexis
Alexis

Reputation: 25163

Debug variable with EJS

I would like to set a global variable in EJS to show/hide some elements. I would like to be able to set this variable once and have it propogate through all the views. What is the best way to do this?

The other parts of my stack are node.js/express/ejs.

Added code for Vadim:

@index = (req, res) ->
    res.render 'index',
    view: 'index'
    gloabals: app.locals    // is there a way to have this line for all controllers?

Upvotes: 0

Views: 1242

Answers (1)

Vadim Baryshev
Vadim Baryshev

Reputation: 26189

You can use express app.locals.

var app = express();
app.locals.someFlag = true;

Upvotes: 1

Related Questions