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

# Update Template

> Update an existing template

## Update

Update a template by ID or alias using the default context.

```go theme={null}
func (s *TemplatesSvcImpl) Update(identifier string, params *UpdateTemplateRequest) (*UpdateTemplateResponse, error)
```

### Parameters

<ParamField path="identifier" type="string" required>
  The template ID or alias.
</ParamField>

<ParamField path="params" type="*UpdateTemplateRequest" required>
  The template update parameters.
</ParamField>

### Returns

Returns an `*UpdateTemplateResponse` containing the updated template ID.

### Example

```go theme={null}
update := &resend.UpdateTemplateRequest{
  Name:    "Updated Welcome Email",
  Subject: "Welcome {{{name}}}!",
  Html:    "<h1>Hello {{{name}}}</h1><p>Updated content</p>",
  Variables: []*resend.TemplateVariable{
    {
      Key:           "name",
      Type:          resend.VariableTypeString,
      FallbackValue: "there",
    },
  },
}

response, err := client.Templates.Update("template_id_or_alias", update)
if err != nil {
  panic(err)
}

fmt.Println("Updated template:", response.Id)
```

***

## UpdateWithContext

Update a template by ID or alias with a custom context.

```go theme={null}
func (s *TemplatesSvcImpl) UpdateWithContext(ctx context.Context, identifier string, params *UpdateTemplateRequest) (*UpdateTemplateResponse, error)
```

### Parameters

<ParamField path="ctx" type="context.Context" required>
  Context for the request, useful for timeouts and cancellation.
</ParamField>

<ParamField path="identifier" type="string" required>
  The template ID or alias.
</ParamField>

<ParamField path="params" type="*UpdateTemplateRequest" required>
  The template update parameters.
</ParamField>

### Returns

Returns an `*UpdateTemplateResponse` containing the updated template ID.

### Example

```go theme={null}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

update := &resend.UpdateTemplateRequest{
  Name: "Updated Template Name",
  Html: "<h1>New content</h1>",
}

response, err := client.Templates.UpdateWithContext(ctx, "welcome-email", update)
if err != nil {
  panic(err)
}
```

***

## Types

### UpdateTemplateRequest

Request payload for updating a template.

```go theme={null}
type UpdateTemplateRequest struct {
  Name      string              `json:"name"`
  Alias     string              `json:"alias,omitempty"`
  From      string              `json:"from,omitempty"`
  Subject   string              `json:"subject,omitempty"`
  ReplyTo   any                 `json:"reply_to,omitempty"` // string or []string
  Html      string              `json:"html"`
  Text      string              `json:"text,omitempty"`
  Variables []*TemplateVariable `json:"variables,omitempty"`
}
```

<ParamField path="Name" type="string" required>
  The name of the template.
</ParamField>

<ParamField path="Alias" type="string">
  A unique alias for the template. Can be used instead of the ID to reference the template.
</ParamField>

<ParamField path="From" type="string">
  The sender email address. Can be a plain email or formatted as "Name \<[email@example.com](mailto:email@example.com)>".
</ParamField>

<ParamField path="Subject" type="string">
  The email subject line. Can include template variables like `{{{variable_name}}}`.
</ParamField>

<ParamField path="ReplyTo" type="any">
  Reply-to email address. Can be a string or array of strings.
</ParamField>

<ParamField path="Html" type="string" required>
  The HTML content of the email template. Use `{{{variable_name}}}` syntax for variables.

  **Important**: All variables referenced in Html must be declared in the Variables array, or the API will return a validation error.
</ParamField>

<ParamField path="Text" type="string">
  Plain text version of the email template.
</ParamField>

<ParamField path="Variables" type="[]*TemplateVariable">
  Array of variable declarations used in the template. All variables referenced in Html or Subject must be declared here.
</ParamField>

### UpdateTemplateResponse

Response from updating a template.

```go theme={null}
type UpdateTemplateResponse struct {
  Id     string `json:"id"`
  Object string `json:"object"`
}
```

<ResponseField name="Id" type="string">
  The unique identifier of the updated template.
</ResponseField>

<ResponseField name="Object" type="string">
  The object type, always "template".
</ResponseField>
