Use fixed placeholder rather then printf
This commit is contained in:
parent
44be377841
commit
27e2a1a02c
|
@ -276,7 +276,7 @@ The following will inject the action link (or button) into the e-mail:
|
||||||
{{ end }}
|
{{ end }}
|
||||||
```
|
```
|
||||||
|
|
||||||
A good practice is to describe action in footer in case of problem when displaying button and CSS
|
A good practice is to describe action in footer in case of problem when displaying button and CSS. The text for the description is provided through the `TroubleText` field of the `Product` struct. The text may contain a placeholder `{ACTION}` which is expected to be replaced with the text of the button. The default value of `TroubleText` is `If you’re having trouble with the button '{ACTION}', copy and paste the URL below into your web browser.`
|
||||||
|
|
||||||
```html
|
```html
|
||||||
{{ with .Email.Body.Actions }}
|
{{ with .Email.Body.Actions }}
|
||||||
|
@ -284,7 +284,7 @@ A good practice is to describe action in footer in case of problem when displayi
|
||||||
<tbody><tr>
|
<tbody><tr>
|
||||||
{{ range $action := . }}
|
{{ range $action := . }}
|
||||||
<td>
|
<td>
|
||||||
<p class="sub">If you’re having trouble with the button '{{ $action.Button.Text }}', copy and paste the URL below into your web browser.</p>
|
<p class="sub">{{$.Hermes.Product.TroubleText | replace "{ACTION}" $action.Button.Text}}</p>
|
||||||
<p class="sub"><a href="{{ $action.Button.Link }}">{{ $action.Button.Link }}</a></p>
|
<p class="sub"><a href="{{ $action.Button.Link }}">{{ $action.Button.Link }}</a></p>
|
||||||
</td>
|
</td>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
14
README.md
14
README.md
|
@ -168,6 +168,20 @@ h := hermes.Hermes{
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To use a custom fallback text at the end of the email, change the `TroubleText` field of the `hermes.Product` struct. The default value is `If you’re having trouble with the button '{ACTION}', copy and paste the URL below into your web browser.`. The `{ACTION}` placeholder will be replaced with the corresponding text of the supplied action button:
|
||||||
|
|
||||||
|
```go
|
||||||
|
// Configure hermes by setting a theme and your product info
|
||||||
|
h := hermes.Hermes{
|
||||||
|
// Optional Theme
|
||||||
|
// Theme: new(Default)
|
||||||
|
Product: hermes.Product{
|
||||||
|
// Custom trouble text
|
||||||
|
Copyright: "If the {ACTION}-button is not working for you, just copy and paste the URL below into your web browser."
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Elements
|
## Elements
|
||||||
|
|
||||||
Hermes supports injecting custom elements such as dictionaries, tables and action buttons into e-mails.
|
Hermes supports injecting custom elements such as dictionaries, tables and action buttons into e-mails.
|
||||||
|
|
|
@ -346,7 +346,7 @@ func (dt *Default) HTMLTemplate() string {
|
||||||
{{ range $action := . }}
|
{{ range $action := . }}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<p class="sub">{{printf $.Hermes.Product.TroubleText $action.Button.Text}}</p>
|
<p class="sub">{{$.Hermes.Product.TroubleText | replace "{ACTION}" $action.Button.Text}}</p>
|
||||||
<p class="sub"><a href="{{ $action.Button.Link }}">{{ $action.Button.Link }}</a></p>
|
<p class="sub"><a href="{{ $action.Button.Link }}">{{ $action.Button.Link }}</a></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -37,7 +37,7 @@ type Product struct {
|
||||||
Link string // e.g. https://matcornic.github.io
|
Link string // e.g. https://matcornic.github.io
|
||||||
Logo string // e.g. https://matcornic.github.io/img/logo.png
|
Logo string // e.g. https://matcornic.github.io/img/logo.png
|
||||||
Copyright string // Copyright © 2017 Hermes. All rights reserved.
|
Copyright string // Copyright © 2017 Hermes. All rights reserved.
|
||||||
TroubleText string // TroubleText is the sentence at the end of the email for users having trouble with the button (default to `If you’re having trouble with the button %s, copy and paste the URL below into your web browser.`)
|
TroubleText string // TroubleText is the sentence at the end of the email for users having trouble with the button (default to `If you’re having trouble with the button '{ACTION}', copy and paste the URL below into your web browser.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Email is the email containing a body
|
// Email is the email containing a body
|
||||||
|
@ -123,7 +123,7 @@ func setDefaultHermesValues(h *Hermes) error {
|
||||||
Product: Product{
|
Product: Product{
|
||||||
Name: "Hermes",
|
Name: "Hermes",
|
||||||
Copyright: "Copyright © 2017 Hermes. All rights reserved.",
|
Copyright: "Copyright © 2017 Hermes. All rights reserved.",
|
||||||
TroubleText: "If you’re having trouble with the button '%s', copy and paste the URL below into your web browser.",
|
TroubleText: "If you’re having trouble with the button '{ACTION}', copy and paste the URL below into your web browser.",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// Merge the given hermes engine configuration with default one
|
// Merge the given hermes engine configuration with default one
|
||||||
|
|
Loading…
Reference in New Issue