Utilizing Jinja Templating in Empress for Sub-Tables

Introduction

Welcome to this guide on how to fetch and display information from sub-tables in Empress using the power of Jinja Templating.

Introduction

Jinja Templating is a feature in Empress that lets you refer to any field on any document type (DocType). This feature can be highly valuable for business users who need to extract and display specific information from their Empress databases.

In any business, it’s often necessary to view, edit, sort, and track information from various sources. This is where Jinja Templating comes in. It allows you to fetch data from any field within your DocType, making it easier to manage and manipulate this information.

However, this guide focuses on a more specific scenario, where you want to fetch data from sub-tables within your DocType—a task that is not as straightforward as it seems.

Prerequisites

Before we dive into the guide, you’ll need to know the variable names of the sub-table and its fields that you want to reference. You can find this information in the ‘Customize Form’ section of the specific DocType in Empress.

Step 1: Displaying Sub-Table Data as a List

First, let’s look at how to display the rows of a sub-table as a list. Here’s how you can do it:

{% for row in doc.items %}
* Item Code: {{ row.get_formatted("item_code", doc) }}
  Quantity: {{ row.get_formatted("qty", doc) }}
  Rate: {{ row.get_formatted("rate", doc) }}
  Amount: {{ row.get_formatted("amount", doc) }}
{% endfor %}

The code above will fetch the item code, quantity, rate, and amount for each item in your sub-table and display them as a list.

Step 2: Displaying Sub-Table Data as a Table

If you prefer to display your data as a table, you can do so with the following code:

|Item Code|Quantity|Rate|Amount|
| --- | --- | --- | --- |
|{{item.item_code }}||||

This will fetch the same fields as before, but this time they will be displayed in a neat table format.

Conclusion

In short, Jinja Templating in Empress is a powerful tool that can aid in the management and manipulation of your business data. Whether you need to fetch data from a sub-table to view, edit, sort, or track information, Jinja Templating helps you do it with ease and flexibility.

Remember, you can always add more fields to fetch from the sub-table by modifying the Jinja template to suit your specific requirements.

This guide has shown you the basics, but don’t hesitate to explore more ways to utilize Jinja Templating to enhance your business processes in Empress. If you need further assistance, visit Empress’s user-friendly support resources for more help.