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

# Templates

> EcoMail Hub users create reusable email templates for creditor profile campaigns.

## Real-World Example

Maya writes a creditor outreach template named Pending Member Follow-Up. She adds a subject and body with merge fields for creditor profile details, previews the email, and saves it. Later, she edits the same template before using it in a campaign.

## Visual Flow

```mermaid placement="top-right" actions={true} theme={"system"}
flowchart TD
    A["User writes template name, subject, and body"] --> B["Portal validates content"]
    B --> C{"Content valid?"}
    C -->|No| D["Show validation error"]
    C -->|Yes| E["Save template for this EcoMail Hub user"]
    E --> F["Template becomes available for campaigns"]
    classDef default fill:#F8FAFC,stroke:#64748B,stroke-width:1.5px,color:#0F172A;
    classDef actor fill:#E0F2FE,stroke:#0284C7,stroke-width:2px,color:#0C4A6E;
    classDef system fill:#F8FAFC,stroke:#64748B,stroke-width:1.5px,color:#0F172A;
    classDef decision fill:#FEF3C7,stroke:#D97706,stroke-width:2px,color:#78350F;
    classDef risk fill:#FEE2E2,stroke:#DC2626,stroke-width:2px,color:#7F1D1D;
    classDef outcome fill:#DCFCE7,stroke:#16A34A,stroke-width:2px,color:#14532D;
    class A actor;
    class B,E system;
    class C decision;
    class D risk;
    class F outcome;
    linkStyle default stroke:#94A3B8,stroke-width:2px;
```

## Template Actions

| Action  | Expected Behavior                                                      |
| ------- | ---------------------------------------------------------------------- |
| Create  | Saves a new owned template with name, subject, and body.               |
| Preview | Lets the user inspect the email content before using it in a campaign. |
| Edit    | Loads an owned template back into the form.                            |
| Delete  | Removes only an owned template and refreshes the list.                 |

## How It Should Work

* It should require template name, subject, and body.
* It should keep templates scoped to the logged-in EcoMail Hub user.
* It should allow preview before sending a campaign.
* It should preserve embedded image content safely when supported by the editor.

## How It Should Not Work

* It should not let one EcoMail Hub user edit or delete another user's template.
* It should not allow duplicate active template names in the same template set.
* It should not send campaign email from a deleted or missing template.

## Developer Notes

* Template body is validated as markdown/editor content and decoded for inline images.
* Campaign sends replace supported template fields with creditor profile values.

## Related App Areas

* `app/Livewire/ConsumerResponseManager/Communications/Template/IndexPage.php`
* `app/Livewire/ConsumerResponseManager/Communications/Template/ListView.php`
* `app/Livewire/ConsumerResponseManager/Forms/TemplateForm.php`
* `app/Services/EcoMailHubTemplateService.php`
