Skip to content

Commit 5bc5167

Browse files
authored
Merge pull request #2003 from umputun/docs/email-template-variables
Document email template variables and plain-text email setup
2 parents 1320b1f + c2cc230 commit 5bc5167

File tree

1 file changed

+76
-0
lines changed
  • site/src/docs/configuration/email

1 file changed

+76
-0
lines changed

site/src/docs/configuration/email/index.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,79 @@ The easiest way to test it is to mount `error_response.html.tmpl`, and then head
218218
![Error_template](images/error_template.png)
219219

220220
If the file is mounted correctly, the page will render the new file content immediately after hitting the refresh button in your browser once you change the file.
221+
222+
### Template variables
223+
224+
Each template has access to different variables. All templates use Go's [text/template](https://pkg.go.dev/text/template) syntax.
225+
226+
#### `email_reply.html.tmpl` — comment notification
227+
228+
Used for notifying users about replies to their comments and for admin notifications about new comments.
229+
230+
| Variable | Type | Description |
231+
|----------|------|-------------|
232+
| `{{.UserName}}` | string | Comment author name |
233+
| `{{.UserPicture}}` | string | Comment author avatar URL |
234+
| `{{.CommentText}}` | string | Comment body (HTML) |
235+
| `{{.CommentLink}}` | string | Direct link to the comment |
236+
| `{{.CommentDate}}` | time.Time | Comment timestamp, format with `{{.CommentDate.Format "02.01.2006 at 15:04"}}` |
237+
| `{{.ParentUserName}}` | string | Parent comment author name |
238+
| `{{.ParentUserPicture}}` | string | Parent comment author avatar URL |
239+
| `{{.ParentCommentText}}` | string | Parent comment body (HTML) |
240+
| `{{.ParentCommentLink}}` | string | Direct link to parent comment |
241+
| `{{.ParentCommentDate}}` | time.Time | Parent comment timestamp |
242+
| `{{.PostTitle}}` | string | Title of the post |
243+
| `{{.Email}}` | string | Recipient email address |
244+
| `{{.UnsubscribeLink}}` | string | Unsubscribe URL |
245+
| `{{.ForAdmin}}` | bool | True when this is an admin notification |
246+
247+
#### `email_confirmation_subscription.html.tmpl` — subscription confirmation
248+
249+
Sent when a user subscribes to email notifications for a comment thread.
250+
251+
| Variable | Type | Description |
252+
|----------|------|-------------|
253+
| `{{.User}}` | string | Username |
254+
| `{{.Token}}` | string | Confirmation token |
255+
| `{{.Email}}` | string | Recipient email address |
256+
| `{{.Site}}` | string | Site name |
257+
| `{{.SubscribeURL}}` | string | Subscription confirmation base URL |
258+
259+
#### `email_confirmation_login.html.tmpl` — login confirmation
260+
261+
Sent when a user logs in via email authentication.
262+
263+
| Variable | Type | Description |
264+
|----------|------|-------------|
265+
| `{{.User}}` | string | Username |
266+
| `{{.Token}}` | string | Login token |
267+
| `{{.Email}}` | string | Recipient email address |
268+
| `{{.Site}}` | string | Site name |
269+
| `{{.Address}}` | string | Recipient address |
270+
271+
### Plain-text emails
272+
273+
The default templates produce HTML emails. To send plain-text emails instead, set `AUTH_EMAIL_CONTENT_TYPE=text/plain` (for login confirmation) or `NOTIFY_EMAIL_CONTENT_TYPE=text/plain` (for notifications), and provide custom templates that output plain text instead of HTML.
274+
275+
Note that `{{.CommentText}}` and `{{.ParentCommentText}}` contain HTML markup. There is no built-in HTML-to-text conversion, so for comments with rich formatting the output will include raw HTML tags.
276+
277+
Example plain-text notification template (`email_reply.html.tmpl`):
278+
279+
```
280+
New reply from {{.UserName}}{{if .PostTitle}} on "{{.PostTitle}}"{{end}}
281+
282+
{{.CommentText}}
283+
{{.CommentDate.Format "02.01.2006 at 15:04"}}
284+
{{.CommentLink}}
285+
{{- if .ParentCommentText}}
286+
287+
In reply to {{.ParentUserName}}:
288+
{{.ParentCommentText}}
289+
{{.ParentCommentLink}}
290+
{{- end}}
291+
292+
Sent to {{.Email}}
293+
{{- if .UnsubscribeLink}}
294+
Unsubscribe: {{.UnsubscribeLink}}
295+
{{- end}}
296+
```

0 commit comments

Comments
 (0)