> 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

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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
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=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
