I'm trying to execute a for loop within one of my ejs templates. It's a board for a game and I want to be able to vary the dimensions with an ejs variable <%= units %>
but I'm having trouble because I'm using this as the parameter for my loop
<div id="boardGridContainer">
<table class="boardGrid">
<% for(var i = 0; i < <%= units %> - 1; i++ ) { %>
<tr>
<% for(var j = 0; j < <%= units %> -1; j++){ %>
<td></td>
<% } %>
</tr>
<% } %>
</table>
</div>
any suggestions on how to accomplish this, or perhaps better ways to do it are appreciated
There is no way to use ejs tags inside of other ejs tags. And you don't need it for your stuff. You can access any exported variables in any ejs tags. For your example:
<div id="boardGridContainer">
<table class="boardGrid">
<% for(var i = 0; i < units - 1; i++ ) { %>
<tr>
<% for(var j = 0; j < units - 1; j++){ %>
<td></td>
<% } %>
</tr>
<% } %>
</table>
</div>