Form email templates - limburgie/c3s GitHub Wiki

A submitted form always results in 2 emails being sent to both the site manager and the visitor who fills out the form. The body of these emails is constructed by the corresponding template files that were configured in c3s.json:

{
    "forms": [
        {
            "name": "Contact",
            "visitorEmail": {
                "subject": "Thank you for your feedback!",
                "contents": "mails/contact_visitor.ftl"
            },
            "managerEmail": {
                "subject": "There is new feedback for your website",
                "contents": "mails/contact_manager.ftl"
            }
        }
    ]
}

So in the example above, filling out the Contact form results in:

  • An email with subject Thank you for your feedback! being sent to the visitor of the site, rendered by the Freemarker template at location mails/contact_visitor.ftl.
  • An email with subject There is new feedback for your website being sent to the manager of the site, rendered by the Freemarker template at location mails/contact_manager.ftl.

Form template variables

The following template variables are available in the form template:

  • params: map of key-value pairs that contain the submitted form values. Both single valued and multivalued parameters can be retrieved.
  • i18n: object representing the resource bundle for the current locale. See Localization for more information.
  • api: instance of the Content API that can be used to query content from the remote content provider. See the Content API page for more information.
  • cart: object representation of the shopping cart, if the site supports e-commerce.

Example

Suppose we have the following form.

<form action="/submit" method="post">
    <label for="name">Your name</label>
    <input id="name" type="text" name="name" required/>

    <label for="email">Your email address</label>
    <input id="email" type="email" name="email" required/>

    <label for="feedback">Your feedback</label>
    <textarea id="feedback" name="feedback" required></textarea>

    <button type="submit">Send</button>
</form>

Then our manager template could look something like this:

<p>Hi there,</p>

<p>${params.name} left you some feedback on your website:</p>

<p><strong>"${params.feedback}"</strong></p>

<p>
    You can reach ${params.name} by the following email address:<br/>
    <a href="mailto:${params.email}">${params.email}</a>
</p>

<p>
    Have a nice day!
</p>

While our visitor template could look something like this:

<p>Dear ${params.name},</p>

<p>
    Thanks a lot for providing us with your valuable feedback.<br/>
    We've registered the following feedback:
</p>

<p><strong>"${params.feedback}"</strong></p>

<p>We will come back to you soon to follow up on your feedback.</p>

<p>
    Have a nice day!<br/>
    C3S
</p>

Both email templates will result in actual emails where the placeholder variables are replaced with the submitted form values.

Evidently, you can always use the ${api} variable as well to query content from the content API into your emails as well, similarly to how pages are constructed.

⚠️ **GitHub.com Fallback** ⚠️