EJS child template parameter
-
I tried a simple parent/child template with ejs rendering engine but could not find a way to pass data to child template.
I am new to jsreport and your advise will be helpful. Thanks.
Ivan
parent template (ejs, text)
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> </head> <% if (items) { %> <table class='invoice-box'> <tr class="headerrow"> <th>name</th> <th>amount</th> <th>child template</th> </tr> <% items.forEach( function(item) { %> <tr> <td><%= item.name %></td> <td><%= item.amount %></td> <td> <% if (item.details) { %> {#child test-1-child-1 @data.child.id=<%= item.id %> } <% } else { %> no details <% } %> </td> </tr> <% }) %> </table> <% } else { %> no result <% } %>
child template (ejs, text)
<div>child.id</div> <div><%= child.id %></div>
sample data
{ "items": [{ "id": 1, "name": "abc", "amount": 1234.56, "details": [{ "id": 1, "description": "line 1" }, { "id": 2, "description": "line 2" }] }] }
However, child.id was not shown. Please see the output below.
<head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> </head> <table class='invoice-box'> <tr class="headerrow"> <th>name</th> <th>amount</th> <th>child template</th> </tr> <tr> <td>abc</td> <td>1234.56</td> <td> <div>child.id</div> <div><%</div> </td> </tr> </table>
-
hi! child templates can't recognize dynamic data passed as params when called like this.
however there is a workaround, and here is an example of how to apply it for your case
-
thank you so much for your reply. I will try the workaround.