Question

I am currently using static pages (will move over to Jade soon) and I want to pass some information into my index.html when the first request is made.

I know this is possible with jade and I wanted to know what my options are if I use a static page?

For example, I need something like this:

 app.get('/', function(req, res) {
    res.render(config.rootPath + '/public/index.html', {data: 'usernamehere'});
});

and in my index.html I have a script tag:

<script>
    var currentUser = data; <-- I know this will never work...
</script>

So should I make a call from my script tag to get the information or is there another way?

Était-ce utile?

La solution

Did you consider express-expose?

"Expose helpers and local variables to the client-side." See the repo.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top