Skip to content

Commit f7cdc2c

Browse files
authored
fix: transient payload in email templates (#1967)
1 parent f95fc08 commit f7cdc2c

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

docs/guides/integrate-with-ory-cloud-through-webhooks.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ Use the `ctx` object to access these fields in your Jsonnet template, for exampl
301301
```jsonnet title="./segment_identify.jsonnet"
302302
function(ctx) {
303303
userId: ctx.identity.id,
304-
customData: ctx.transient_payload.custom_data
304+
customData: ctx.flow.transient_payload.custom_data
305305
traits: {
306306
email: ctx.identity.traits.email,
307307
name: ctx.identity.traits.name,

docs/kratos/emails-sms/05_custom-email-templates.mdx

+47
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,50 @@ Since metadata is not validated by Ory Identities, missing entries or unexpected
508508
process. If the system encounters errors in the rendering process, Ory Identities uses the default templates.
509509

510510
:::
511+
512+
### Transient payload in templates
513+
514+
The transient payload allows you to pass additional data along with certain self-service flows. Transient payloads can be used for
515+
passing temporary information to your email template without storing it permanently.
516+
517+
The following `example_key` transient payload
518+
519+
```
520+
...
521+
traits: {
522+
523+
},
524+
transient_payload: {
525+
example_key: "This is an example value"
526+
},
527+
...
528+
```
529+
530+
can be accessed in the email template using `{{index .TransientPayload "example_key"}}`
531+
532+
```gotmpl
533+
534+
<h1>Recovery Details</h1>
535+
<p>To: {{.To}}</p>
536+
<p>Recovery URL: {{.RecoveryURL}}</p>
537+
<p>Transient Payload: {{index .TransientPayload "example_key"}}</p>
538+
<p>
539+
{{- if eq (index .TransientPayload "lang") "foo" -}}
540+
FOO
541+
{{- else -}}
542+
BAR
543+
{{- end -}}
544+
</p>
545+
```
546+
547+
This results into the following email to be sent to the user.
548+
549+
```gotmpl
550+
<h1>Recovery Details</h1>
551+
552+
<p>Recovery URL: https://example.com/recover</p>
553+
<p>Transient Payload: This is an example value</p>
554+
<p>
555+
BAR
556+
</p>
557+
```

0 commit comments

Comments
 (0)