-1

I am using EJS as my Express view engine, and I'm trying to 'expose' a variable in a partial so that I can use it in the *.ejs which 'include' it, but I don't know how to do it.

partial.ejs
<% var jsUrl = 'sth'; %>

test.ejs
<script tpye="text/javascript" src="<%= jsUrl %>"></script>

When I render test.ejs, I want to pass nothing to test.ejs.like:

res.render('test.ejs'); 

Instead, I want to use the variable which defined in the partial. Any help is appreciated.

Boris
  • 555
  • 7
  • 22

1 Answers1

1

I think that this is impossible in this case. Look at my JUST template engine. It has a similar syntax to the EJS but it more powerful. In JUST you can redefine blocks in parent templates, template inheritance and pass parameters between parts.

Vadim Baryshev
  • 25,689
  • 4
  • 56
  • 48
  • Thanks for recommending JUST. Can I use JUST directly doing something like app.set('view engine', 'just'); in Express? And how is its performance? – Boris Mar 16 '12 at 03:50
  • Unfortunately I do not use express. I work directly with [connect](https://github.com/senchalabs/connect). With a set of modules, it satisfies all my requirements. I think you can bind JUST to express through app.register function. But now I'm not ready to give a source code for this. JUST benchmarks are in development. At the same templates with EJS performance should be about the same. But not all functions can be compared because in the EJS they are not present. Templates compiles only one time and cached. – Vadim Baryshev Mar 16 '12 at 04:41