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.
Thanks…

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"]},
    fields=["*"]
    )[0]
%}
{%
 set child_document = frappe.get_all("Child Doctype",
    filters={"parent": ["=", document.name]},
    fields=["*"]
    )
%}
<h1>Parent document</h1>
<ul>
     {% for key, value in document.items() %}
        <li>{{ key }}: {{ value }}</li>
    {% endfor %}
</ul>
<h2>Child Table for Parent document</h2>
    {% for row in child_document %}
    <br>
    <h3>New Child Item {{1+ loop.index0 }}</h3>
    <ul>    
        {% for key, value in row.items() %}
			<li>{{ key }}: {{ value }}</li>
		{% endfor %}
	</ul>	
    {% 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
    frappe.sendmail(
        recipients=["recipient@example.com"],
        subject="Email Subject",
        template="path/to/your_email_template",
        args={"doc": doc},
    )

Jinja Template

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

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