Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Add topic for new email template directives #6107

Merged
merged 20 commits into from
Dec 11, 2019
Merged

Conversation

dobooth
Copy link
Contributor

@dobooth dobooth commented Dec 3, 2019

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.

@dobooth dobooth added New Topic A major update published as an entirely new document 2.3.4 Magento 2.3.4 changes labels Dec 3, 2019
@dobooth dobooth self-assigned this Dec 3, 2019

## 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.
Copy link
Contributor

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.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dobooth dobooth requested a review from nathanjosiah December 10, 2019 15:17
```

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}}`.
Copy link
Contributor

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.

Copy link
Contributor Author

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}}`.
Copy link
Contributor

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')]);
Copy link
Contributor

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”.
Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

Copy link
Contributor

@nathanjosiah nathanjosiah left a 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.

@dobooth
Copy link
Contributor Author

dobooth commented Dec 10, 2019

Reached out to architects about updating the supported client list. I can update that in a separate PR once I hear back.

@dobooth dobooth requested a review from keharper December 10, 2019 18:27
Copy link
Contributor

@keharper keharper left a 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:
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor

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.

@dobooth
Copy link
Contributor Author

dobooth commented Dec 10, 2019

running tests

@dobooth dobooth changed the base branch from master to 2.3.4-develop December 10, 2019 19:26
@dobooth dobooth changed the base branch from 2.3.4-develop to master December 10, 2019 19:26
@dobooth dobooth changed the base branch from master to 2.3.4-develop December 11, 2019 15:40
@dobooth
Copy link
Contributor Author

dobooth commented Dec 11, 2019

running tests

@dobooth
Copy link
Contributor Author

dobooth commented Dec 11, 2019

running tests

@dobooth dobooth merged commit d29317a into 2.3.4-develop Dec 11, 2019
@ghost
Copy link

ghost commented Dec 11, 2019

Hi @dobooth, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
2.3.4 Magento 2.3.4 changes New Topic A major update published as an entirely new document
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants