{mailtemplate:template:to}

Description

Sends one of the slice/site e-mail templates to the given address. The first argument is the numeric id of an e-mail template (the templates editable under the slice e-mail settings); it must belong to a slice in the same site as the rendering context, otherwise nothing is sent. The second argument is one e-mail address, or a JSON array of addresses. The current item is passed to the template, so item aliases (the _#ITEM_ID style placeholders) expand inside the template body and subject. Returns 1 when the mail was accepted for sending, and an empty string otherwise (no template, non-numeric or empty first argument, template not owned by a related slice, or empty recipient). Because an empty or non-numeric first argument sends nothing and returns empty, the command doubles as a conditional gate: feed it a template id only when you actually want to send. WARNING: this is a side effect. It runs on every page render, so an unguarded call sends mail every time the page is built. Guard it with a condition so it only fires on the intended request.

Parameters

template required

Numeric id of an e-mail template to send. The template must belong to a slice in the same site as the current render; otherwise nothing is sent and the result is empty. An empty or non-numeric value sends nothing and returns empty, which lets you use the first argument as a send-or-not condition.

to required

Recipient address, or a JSON array of addresses for several recipients, for example ["editor@example.org","info@example.org"]. An empty recipient list sends nothing and returns empty.

Examples

test{strlen:{mailtemplate::editor@example.org}}
Expected0
Actual0
An empty first argument is the off state: nothing is sent and the result is empty (here measured as length 0). This is the basis of the conditional-send pattern - pass a template id only when you mean to send.
test{strlen:{mailtemplate:none:editor@example.org}}
Expected0
Actual0
The template id must be numeric. A non-numeric value (here the word none) is treated as no template: nothing is sent and the result is empty.
test{strlen:{mailtemplate:{if1:{qss:send}:874}:editor@example.org}}
Expected0
Actual0
The real-world guard. {if1:{qss:send}:874} returns the template id 874 only when the page is called with ?send=1, otherwise it returns empty, so mailtemplate sends nothing. Rendered here without that query flag, the result is empty (length 0). Replace 874 with your own template id.
virtual{mailtemplate:874:editor@example.org}
Expected(1 when template 874 belongs to this site and the mail is queued, empty otherwise)
The plain send call: deliver e-mail template 874 to one address. Returns 1 when the mail is accepted, empty otherwise. Marked illustrative because it has a side effect (it sends) and depends on template 874 existing in this site; in this documentation site no such template is related, so nothing is sent here.
virtual{mailtemplate:874:["editor@example.org","info@example.org"]}
Expected(1 when the mail is queued, empty otherwise)
Pass a JSON array as the recipient to send to several addresses at once. The first two are sent immediately and the rest are queued. Illustrative for the same reason as the single-recipient call.