tj / ejs

Embedded JavaScript templates for node
4.47k stars 513 forks source link

How to handle tag <%- jsVariable %> where jsVariable is a string variable with several <%= %> #225

Open o1lab opened 7 years ago

o1lab commented 7 years ago

How to handle tag <%- jsVariable %> where jsVariable is a string variable with several <%= %>

Usecase here:

<% for(var i = 0 ; i < largeObject.elementArray.length; ++i) {%>
    <%-largeObject.elementArray[i].myTemplate%>
<%}%>

'.myTemplate' is a string variable - examples below:

largeObject.elementArray[i].myTemplate = '<%=largeObject.elementArray[i].variable_1 + largeObject.elementArray[i].variable_7 + largeObject.elementArray[i].variable_12%>'

or

largeObject.elementArray[i].myTemplate = '<%=largeObject.elementArray[i].variable_1 + largeObject.elementArray[i].variable_5 + largeObject.elementArray[i].variable_14%>'

'myTemplate' variable derivation is fairly complex and hence it is pre-calculated string - but then how do I expand 'myTemplate' string now.

My EJS knowledge is basic - I might be missing some technical correct terms explaining this problem.

mde commented 7 years ago

This version of EJS is no longer maintained. The current one, available on NPM, is here: https://github.com/mde/ejs

Please ask this question over there, so other folks can follow the discussion. Thanks.