# 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
