> ## Documentation Index
> Fetch the complete documentation index at: https://docs.safesquid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Templates

<Note>
  CLI man page: `safesquid-templates(5)`
</Note>

The **Templates** section (`safesquid-templates(5)`) configures block pages and error bodies served when SafeSquid denies traffic or returns configured errors.

## Core mechanics

### Resolution order

1. Walk configured rows top-down.
2. Skip disabled or empty Name.
3. **Profiles** gate must pass (blank = any).
4. Case-insensitive Name match — **first match wins**.
5. Else built-in `PAGES[]` defaults.
6. Else log undefined template error.

<Frame caption="Template resolution">
  <img src="https://mintcdn.com/safe-squid-labs-12a0916f/VRx-_vpMam8ezhZz/images/admin_guide/templates_flowchart.svg?fit=max&auto=format&n=VRx-_vpMam8ezhZz&q=85&s=7de4b54db5b1e48afa8095ab9c0039de" alt="Template get flow" width="480" height="300" data-path="images/admin_guide/templates_flowchart.svg" />
</Frame>

### FILE vs EXECUTABLE

* **FILE** — Preloaded at config load from Name path or File fallback. MIME blank → `application/octet-stream`.
* **EXECUTABLE** — Run at send time; stdout must be HTTP response (`ENABLE_EXTERNAL` required).

### Send

The block template uses the caller status or the row Response code. Adds `X-SafeSquid-Template` header. HTML built-ins may inject stylesheet.

## Examples

<Tip>
  ### Branded block page

  **Config:** Name `company-block`, FILE, Parsable on, code 403.

  **Result:** Access Profiles Deny serves HTML with substituted variables.
</Tip>

<Tip>
  ### Profile-specific block

  **Config:** two rows same Name `block`; row A Profiles `staff` above row B blank profiles.

  **Result:** staff connections get staff template first.
</Tip>

## How to verify

1. Trigger block referencing template name.
2. DEBUG + TEMPLATE native logs.
3. Check `X-SafeSquid-Template` response header.


## Related topics

- [Clam Antivirus](/use_cases/malware_scanning/clamav_malware_scanning.md)
- [Custom Templates](/use_cases/customisation/custom_templates.md)
- [Compliance Templates](/use_cases/access_restriction/compliance_templates.md)
- [Data Leakage Prevention](/use_cases/data_leakage_prevention/data_leakage_prevention.md)
- [Customisation](/use_cases/customisation/customisation.md)
