-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add topic for new email template directives #6107
Conversation
|
||
## Changes to the custom email template workflow | ||
|
||
In Magento 2.3.4, custom email templates are only allowed to use scalar values for variable data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As of Magento 2.3.4,
(I'm just leaving a comment here to determine whether I'm experiencing problems posting review comments everywhere, or just in a certain other PR.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
``` | ||
|
||
The new variable is now available within the email template as `{{lifetime_spend}}`. | ||
Note in the class above, we also defined the filter `shouldBold`. We can use that with `{{lifetime_spend should_bold=1}}`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should_bold is a configurable parameter not a filter. The default filter that is applied is nl2br
as defined in the getDefaultFilters
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
|
||
The new variable is now available within the email template as `{{lifetime_spend}}`. | ||
Note in the class above, we also defined the filter `shouldBold`. We can use that with `{{lifetime_spend should_bold=1}}`. | ||
You may also use multiple filters within a var statement: `{{lifetime_spend should_bold=1 |escape}}`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned, should_bold
is a parameter so multiple filters would look like this:
You may also use multiple filters within a var statement: `{{lifetime_spend should_bold=1 |escape|nl2br}}`.
For example, if we have: | ||
|
||
```php | ||
$template->setVariables(['customer_data'=>new DataObject('mykey' => 'foo')]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the key should be my_key not mykey because the call below getMyKey will resolve to getData('my_key') due to the casing.
{{mydir dir fname=$customer_data.name.first_name}} | ||
``` | ||
|
||
it will resolve to “John”. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this whole section 👍
We refer to this as 'strict mode' for email templates. | ||
All default templates have been converted to this strict mode. | ||
|
||
All existing custom email templates will continue to work after upgrading to 2.3.4. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this may be worthy of calling out more, maybe in one of the pull quote style info boxes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github won't let me add anymore specific comments for some reason. I'm getting javascript errors when I try to submit them so looks like github is broken for me.
My last comment is regarding the supported email clients list:
This is horribly outdated. I'm not sure what the official list is but we mention we only support android 4.2 at the latest and the current version is 10. I'm not sure who owns this but this is pretty embarrassing if this is accurate.
Reached out to architects about updating the supported client list. I can update that in a separate PR once I hear back. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, pending some style changes
@@ -111,7 +72,7 @@ To add a variable to your template content: | |||
1. In the Magento Admin, navigate to **MARKETING** > Communications > **Email Templates** | |||
1. Create a new template or edit an existing template. | |||
1. Click to place the cursor in the text in which to insert the variable. | |||
1. Click **Insert Variable**. A pop-up containing a list of variables opens, including custom variables. The variables in the **Store Contact Information** are available in all email templates whereas the variables in the **Template Variables** section are specific to the template you're editing. The following figure shows an example: | |||
1. Click **Insert Variable**. A pop-up containing a list of variables opens, including custom variables. The variables in the **Store Contact Information** are available in all email templates whereas the variables in the **Template Variables** section are specific to the template you are editing and the extensions you may have installed. The following figure shows an example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure this info makes it into merchdocs
To be more specific, methods can no longer be called from variables from either the `var` directive or when used as parameters. | ||
For example `{{var order.getEmailCustomerNote()}}` or `{{something myVar=$obj.method()}}` will fail to resolve. | ||
|
||
A 'custom email template' is any new template created in the Magento admin **Marketing** > Communications > **Email Templates** > **Add New Template** area. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A 'custom email template' is any new template created in the Magento admin **Marketing** > Communications > **Email Templates** > **Add New Template** area. | |
A 'custom email template' is any new template created in the Magento Admin **Marketing** > Communications > **Email Templates** > **Add New Template** area. |
} | ||
``` | ||
|
||
and save the file to <Vendor>/<module>/Model. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge this line with #84 so that you don't have a fragment after the long code sample.
|
||
## Advanced filtering | ||
|
||
As part of this change, we have removed the limit of processing 2 filters per directive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As part of this change, we have removed the limit of processing 2 filters per directive. | |
As part of this change, we have removed the limit of processing two filters per directive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change to
As of Magento 2.3.4, you can now process more than two filters per directive. You can now specify directives like {{var order_data.shipping_description|filter1|filter2|filter3}}
.
In other words, emphasize what the reader can do, not what we did.
running tests |
running tests |
running tests |
Hi @dobooth, thank you for your contribution! |
Purpose of this pull request
This pull request (PR) explains changes to the email template workflow.
Affected DevDocs pages
whatsnew
Added the Migrating custom email templates topic to the Frontend Developer Guide.