How can I loop through a child table using jinja

@rmehta @MartinHBramwell @trentmu @gsarunk I have a child table, I want to share the same as a email template. For that I have written jinja code but it doesn’t loop through the each row values.

How to pass the dynamic values inside a jinja code.

Hi @Deepu1117,

I think, first do check the Fetch child table values using Jinja tags Documentation.
Maybe it is helpful for you.

Thank You!

Thank you! for your response…Its a helpful article. But I don’t want to do these through print format. Is there any alternate solution there?

Could you please let us know what is the final output you are trying to achieve

This is how I solved it on web page

{% set document = frappe.get_all('My Doctype Name', 
    filters={'name':['=', "DocName"]},
 set child_document = frappe.get_all("Child Doctype",
    filters={"parent": ["=",]},
<h1>Parent document</h1>
     {% for key, value in document.items() %}
        <li>{{ key }}: {{ value }}</li>
    {% endfor %}
<h2>Child Table for Parent document</h2>
    {% for row in child_document %}
    <h3>New Child Item {{1+ loop.index0 }}</h3>
        {% for key, value in row.items() %}
			<li>{{ key }}: {{ value }}</li>
		{% endfor %}
    {% endfor %}

File which is Sending the Email Template

import frappe

def send_email_with_document(docname):
    # Fetch the document
    doc = frappe.get_doc("YourDoctype", docname)
    # Pass the document to the email template context
        subject="Email Subject",
        args={"doc": doc},

Jinja Template

<p>Document Name: {{ }}</p>
<p>Document Field 1: {{ doc.field_1 }}</p>
<p>Document Field 2: {{ doc.field_2 }}</p>

<p>Child Table:</p>
{% for row in doc.child_table %}
    <li>{{ row.field_name }}</li>
{% endfor %}