> For the complete documentation index, see [llms.txt](https://help.sdocs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-add-custom-headers-and-footers-to-tables.md).

# How To: Add Custom Headers and Footers to Tables

Add custom headers, section breaks, and summary rows to related list tables.

Use manual table markup around line item output when you need extra structure above or below the data.

### Problem

You want to add total rows, summaries, or custom headers to your related list tables.

### Solution 1: Custom Column Headers

**Instead of field API names:**

```
<!--{{!
<lineitems>
<listname>opportunitylineitems</listname>
<column header="Product Name">PricebookEntry.Product2.name</column>
<column header="Qty">quantity</column>
<column header="Price Each" prefix="$" format-number="#,###.##">unitprice</column>
<column header="Line Total" prefix="$" format-number="#,###.##">totalprice</column>
</lineitems>
}}-->
```

### Solution 2: Summary Rows

**Add a total after the line items:**

```
<table>
  <thead>
    <tr>
      <th>Product</th>
      <th>Quantity</th>
      <th>Price</th>
      <th>Total</th>
    </tr>
  </thead>
  <tbody>
<!--{{!
<lineitems>
<listname>opportunitylineitems</listname>
<column>PricebookEntry.Product2.name</column>
<column>quantity</column>
<column prefix="$" format-number="#,###.##">unitprice</column>
<column prefix="$" format-number="#,###.##">totalprice</column>
</lineitems>
}}-->
    <tr>
      <td colspan="3" style="text-align: right;"><strong>TOTAL:</strong></td>
      <td><strong>${{!Opportunity.Amount format-number="#,###.##"}}</strong></td>
    </tr>
  </tbody>
</table>
```

### Solution 3: Section Headers

**Group products by category:**

```
<h3>Hardware Products</h3>
<!--{{!
<lineitemsSOQL>
<soql>SELECT Name, UnitPrice FROM OpportunityLineItem WHERE OpportunityId = '{{!Opportunity.Id}}' AND Product_Category__c = 'Hardware'</soql>
<column>Name</column>
<column prefix="$" format-number="#,###.##">UnitPrice</column>
</lineitemsSOQL>
}}-->

<h3>Software Products</h3>
<!--{{!
<lineitemsSOQL>
<soql>SELECT Name, UnitPrice FROM OpportunityLineItem WHERE OpportunityId = '{{!Opportunity.Id}}' AND Product_Category__c = 'Software'</soql>
<column>Name</column>
<column prefix="$" format-number="#,###.##">UnitPrice</column>
</lineitemsSOQL>
}}-->
```

### Tips

* Use `header="Text"` for simple column renaming.
* Add summary rows manually after the line item block.
* Use `colspan` to span summary cells across columns.
* Use separate line item blocks to segment data.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.sdocs.com/sdocs/advanced-template-logic/template-attributes/template-attributes-how-to-guides/how-to-add-custom-headers-and-footers-to-tables.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
