A Notification object stores information about your email notification. Each notification belongs to a single form, but a form can have many notifications. Whenever you're dealing with a notification in your template, you're actually working with a Notification
object.
Attribute | Description |
---|---|
id | ID of the notification. |
formId | The Form ID this notification belongs to. |
templateId | The Email Template used by this notification. |
pdfTemplateId | The PDF Template used by this notification. |
name | The control panel name for this notification. |
enabled | Whether the notification is enabled. |
subject | The subject for the email. |
recipients | Determines what type of recipient will be. Either email or conditions . |
to | The email address(es) the notification will be sent to. |
toConditions | Conditional logic rules for who to sent the notification to. |
cc | The email address(es) the notification will be cc-ed to. |
bcc | The email address(es) the notification will be bcc-ed to. |
replyTo | The reply-to email for the notification. |
replyToName | The reply-to name for the notification. |
from | The email address of the sender for the email notification. |
fromName | The name of the sender for the email notification. |
content | The raw JSON-based block content for the email. See also Content. |
attachFiles | Whether to attach user-uploaded files to the notification. |
attachPdf | Whether to attach a PDF template to the notification. |
enableCondition | Whether to allow conditional logic for sending the notification. |
conditions | Conditional logic rules for sending the notification. |
Method | Description |
---|---|
getParsedContent() | Returns the rendered HTML as generated by the rich text editor in the control panel. |
We use TipTap (opens new window) - a Vue-based rich text field to allow users to add content to their email notification. This in turn, uses ProseMirror (opens new window). ProseMirror stores all HTML content as JSON-blocks of content, rather than the raw, generated HTML.
As such, when you want to get the HTML for an email notification, you should use getParsedContent()
, but you can also use content
to get the raw array of content blocks, if you want fine-grained control about how to output the DOM nodes. We would highly recommend the following packages (with Formie uses) to parse and handle this content:
In addition, we also use a cut-down version of TipTap (opens new window) for a number of fields in a notification, namely the email fields. This allows easy picking of emails, both from the system and email fields, without having to worry about Twig syntax, field handles, or anything client-unfriendly.
These variables are stored in shorthand Twig format, and are parsed before they are used. For example, you might have an emailAddress
field in your form, and you want to use in the to
address. You can either pick this variable from the variable dropdown field in the control panel, or you can write {emailAddress}
which is the equivalent. In fact, this is how the content is stored.
If you wanted to show this content in the email, directly outputting the to
attribute would render {emailAddress}
- probably not what you want. Instead, you can wrap this content in the variable-parsing function Formie itself uses.
{% set toEmail = craft.formie.getParsedValue(notification.to, submission) %}
$toEmail = \verbb\formie\helpers\Variables::getParsedValue($notification->to, $submission);
For the above, it's a requirement to provide both the string that you want to parse, and the submission, which contains the object of content to get values from.