Most Common Jinja Issues

How do I solve the error showing the Unexpected char '&'?


When an email fails to render and gets stuck in the loading phase with an error, it means there is a blank space in the code where it is not expected. Jinja syntax is sensitive to such errors and fails to execute.
Additionally, if the error starts with Unexpected char ‘&’, check the error message to locate the part of the code where the character ‘&’ is contained. For example, in the above image, the blank space (indicated by “ ” or non-breaking space) is between the number 5 and the enclosing of the jinja expression brackets.
Once you have located the blank space, go back to the code in the editor and delete the blank space. Similarly, check and delete other blank spaces indicated in the error and render the email once again.

How do I solve an error stating None has no attribute value?

588588 533533

When an error occurs with a message similar to None/None type has no attribute/None has no attribute value, as displayed in the image above, it means that an empty object has been accessed. This can happen in a scenario where the code contains a variable that is expected to be added with an object (such as an item for a catalog based on its id) but the code fails to do so. For example, providing a non-existent item_id which cause the item_by_id function to fail to fetch any item from the catalog. When working with the same object later, rendering fails as the object does not exist.
When encountering such an error, it is recommended to add a condition that checks whether the object exists or not. This practice can avoid unnecessary rendering issues.
Conditions are added to the code in the above image (see image below). This condition prevents an incorrect assessment of the object in case it does not exist. The {% if item%} results in True if there is a value assigned to the variable. If the result is False, the execution of the code within is not executed if the code calls for the given object.

520520 642642


Did this article help you?

Please provide your feedback. We would like to know if our help center is effective in solving your queries. You can also leave comments and suggestions on how we can make our help articles better. You can also suggest topics you’d like us to cover.