Solved: Undefined Index: DirectiveName in SimpleDirective.php in Magento 2
Is your Magento 2 store not working properly when an email is supposed to be triggered? Well, this can be because of a custom email template. Follow me till the end of this post to find the solution. 🎯
In Magento 2, different email notifications are sent to the customers and admins for various activities. The merchants can customize the email templates according to their needs. Sometimes these custom email templates can create compatibility issues after Magento upgrades. Recently, I encountered one such issue in our client’s Magento store, which was freshly upgraded to Magento 2.3.4.
Magento was throwing error 500 when the emails were supposed to be sent through custom templates, i.e. new customer registration, reset customer password, order success, etc.
The error log showed: “Undefined Index: DirectiveName in vendor\magento\framework\Filter\DirectiveProcessor\Simple Directive.php in Magento 2“.
This is because of the restrictions on the usage of custom variables in Magento 2.3.4 (Adobe Commerce). It can be easily solved by following the custom email template migration guide released by Magento.
Let’s see how to fix Undefined Index: DirectiveName in SimpleDirective.php in Magento 2.
Method to Solve Undefined Index: DirectiveName in SimpleDirective.php in Magento 2
In Magento 2.3.4, there have been changes in the custom email template workflow. All the email templates have been converted to ‘strict mode’ as referred to by the Magento custom email template migration guide.
Referring to the same guide, I came to know that the issue was caused by the space in the custom directive code. According to the official resource, spaces should not be used next to the braces:
Correct: {{var subscriber_data.confirmation_link}}
Incorrect: {{ var subscriber_data.confirmation_link }}
In order to solve the issue:
- Step 1: Log into your Magento admin and go to Marketing > Communications > Email Templates.
- Step 2: Select the custom email template and search for
{{
in the template content to find the directive code with space next to braces. - Step 3: Remove the spaces after
{{
and before}}
. - Step 4: Save the template.
& you’re done!
Magento 2 custom email templates will start working again..!
Related Solution: Call to Undefined Function bccomp() in Magento 2
Conclusion
The custom email template incompatibility in Magento 2.3.4 is a crucial issue. It should be addressed earnestly not to put your store’s customer experience at stake. It can be easily solved by following Magento’s custom email template migration guide.
I hope the solution provided here will help you solve the issue.
Still need any help? Comment down your queries; I’d be happy to help you. 😇
Do not forget to share this Magento solution with your friends via social media. 😃
Thanks for reading. 🍀
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
Prev
How To Auto Select Shipping Method in Magento 2
How to Add Canonical Tags in Magento 2
Next