Hey Guys! How do I style my kratos email template...
# talk-kratos
f
Hey Guys! How do I style my kratos email templates using Html /Css and send the username of the user in the recovery email?
m
Hey @flat-rose-25983! Check out this document: https://www.ory.sh/kratos/docs/concepts/email-sms/
Templates use the golang template engine in the
text/template
package for rendering the
email.subject.gotmpl
and
email.body.plaintext.gotmpl
templates, and the
html/template
package for rendering the
email.body.gotmpl
template: https://pkg.go.dev/text/template > https://pkg.go.dev/html/template
Templates can use the Sprig library, which provides more than 100 commonly used template functions: http://masterminds.github.io/sprig/
Let me know if that helped 🙌
🙌 1
f
Thanks Vincent. Is there a way to add username in email body ? I have tried this {{.Identity.traits.name}} but no luck.
m
There is a way for sure, but I have to look as well how exactly😅 I will ask around a bit and get back to you.
Hey @flat-rose-25983 I think you just need
Copy code
{{ upper .Identity.traits.firstName }},
https://www.ory.sh/kratos/docs/concepts/email-sms/#nested-templates or {{ .Identity.traits.firstName }} It depends how your identity schema looks, can you share it maybe?
f
Hey @magnificent-energy-493 Thanks. Here is my schema:
Copy code
{
  "$id": "<https://schemas.ory.sh/presets/kratos/quickstart/email-password/identity.schema.json>",
  "$schema": "<http://json-schema.org/draft-07/schema#>",
  "title": "Person",
  "type": "object",
  "properties": {
    "traits": {
      "type": "object",
      "properties": {
        "email": {
          "type": "string",
          "format": "email",
          "title": "E-Mail",
          "minLength": 3,
          "<http://ory.sh/kratos|ory.sh/kratos>": {
            "credentials": {
              "password": {
                "identifier": true
              }
            },
            "verification": {
              "via": "email"
            },
            "recovery": {
              "via": "email"
            }
          }
        },
        "name": {
          "title": "Name",
          "type": "string"
        }
      },
      "required": [
        "email"
      ],
      "additionalProperties": false
    }
  }
}
m
Hm then
{{ .Identity.traits.name }}
should work 🤔 Are you able to share a reproducible repo? That would help in figuring out where the issue is. You can also share it private with my github if you prefer
f
Hey @magnificent-energy-493, Still cannot make it work. It says Identity does not exist in RecoveryModel