
- August 10, 2021
- admin
- 0 Comments
- Magento 2
Error in Magento 2 Email Template Would Cause You Much
Recently one of our customers reported an issue with his email, where a strange error log appeared.
When looked at the exception log could find the below:
bash-4.2$ cat var/log/exception.log
main.CRITICAL: Notice: Undefined offset: 1 in /vendor/magento/framework/Filter/DirectiveProcessor/DependDirective.php on line 44 {"exception":"[object] (Exception(code: 0): Notice: Undefined offset: 1 in
Root Cause Analysis
This issue happens due to error in the email template. To identify the cause, try previewing from email template (Marketing > Communications > Email Templates)

Check if there any custom templates and preview them individually. Preview will not work if there are issues in the template. Narrow down by removing the email content would help analysing the issue. In this case, the issue found in below the line of email template:
{{template config_path="design/email/footer_template"}}

The issue might be due to missing closing {{/depend}}, or {{/if}} etc. from the template.
Check if there are any email template overrides that causes the issue.
In this case, I found an email override with the below content
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<!--@subject {{trans "Footer"}} @-->
<!--@vars {
"var store.getFrontendName()":"Store Name"
} @-->
<!-- End Content -->
</td>
</tr>
<tr>
<td class="footer">
<table>
<tr>
<td>
{{depend store_phone}}
<p class="phone">
{{trans '<a href="tel:%store_phone">%store_phone</a>' store_phone=$store_phone |raw}}
</p>
{{/depend}}
{{depend store_hours}}
<p class="hours">
{{trans 'Hours of Operation:<br /><span class="no-link">%store_hours</span>.' store_hours=$store_hours |raw}}
</p>
{{/depend}}
</td>
<td>
</td>
<td>
<p class="address">
{{var store.getFormattedAddress()|raw}}
</p>
{{depend store_email}}
<br>{{trans 'Email us at <a href="mailto:%store_email">%store_email</a>' store_email=$store_email|raw}}
{{depend store_email}}
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- End wrapper table -->
</body>
Note {{depend store_email}} in the above content is not closed properly. Rewritten like the below solved the issue.
{{depend store_email}}
<br>{{trans 'Email us at <a href="mailto:%store_email">%store_email</a>' store_email=$store_email|raw}}
{{/depend }}
Once the template is updated, ensure to run the below commands.
php bin/magento setup:static-content:deploy
php bin/magento cache:clean
php bin/magento cache:flush
Please comment in below if you face any issue further assistance. Happy to help you out.
Leave a Comment