How to working with child template



  • Please, I have two table :

    client:

    atributes:
    id
    name

    items:
    id
    description

    and I need to do a report that show this way:

    name: John
    description: pencil
    description: pen
    name: Peter
    description: erase
    description: pen

    I need to use child templates for this, but I don't know how to implement. Do you have someone example?

    Best regards


  • administrators

    hi! can you create an example that demonstrate your desired output here? it does not matter if it is just static content, i just want to understand more what is the way that you expect your data being organized in your report. also please make sure to upload a sample of your data so i can have an idea of the shape of your data input.



  • I Sorry, I'm Brazilian, and, my English is still not very good, so I often do not express myself correctly in the language. I was able to solve the problem, I will post below so others can use this example:

    I have three files: clientes(parent template), childClientes(child template) and dataClientes(data in json)
    The parent template will show name and document, and child template will show items descriptions.
    Below is the content of the files:

    dataClientes(data in json)

    {
    "students" : [
    {
    "id": 1,
    "name":"Robert",
    "document": "324234234",
    "items":[{"description":"pen"}, {"description":"pencil"}]

        }, 
        {
            "id":2,
            "name":"Peter", 
            "document": "3423423", 
            "items":[{"description":"erase"}, {"description":"pen"}]
            
        }  
    ]
    

    }

    clientes(parent template)

    <meta charset="UTF-8">
    <br><br>
    <table width="100%">
    <p><th align="left" width="50%">Name</th></p>
    <p></p><th align="left" width="50%">Document</th></p>
    </table>
    {{#each students}}

    <table width="100%">
    <tr>
    <td width="50%">
    {{name}}
    </td>
    <td width=50%>
    {{document}}
    </td>
    </tr>
    <tr> </tr>
    <tr>
    {{#each items}}
    {#child childClientes @data.value= {{description}} }
    {{/each}}

    </tr>
    {{/each}}
    

    </table>

    childClientes(child template)

    <table>
    <tr>
    <td>    {{value}}</td>
    </tr>
    </table>


  • administrators

    nice, glad that you found a solution and thanks for sharing your approach. an alternative solution is to use assets instead of child templates just for your information, maybe it can be useful to you in the future.



  • Thank for you bjrmatos for feedback


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.