Skip to content

Commit

Permalink
Fix the MJML template, and document our MJML template tag
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchrisadams committed Jul 12, 2024
1 parent 7aa4b91 commit bb0965c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cl8/templates/invite_new_profile.mjml.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<mj-body>
<mj-section>
<mj-column>
<mj-text font-size="18px" line-height=1.5>
<mj-text font-size="18px" line-height="1.5">
<p>Dear {{ profile.name }},</p>
<p>Welcome to {{ constellation }}.</p>
<p>
Expand Down
2 changes: 1 addition & 1 deletion cl8/templates/passwordless_default_token_email.mjml.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<mj-body>
<mj-section>
<mj-column>
<mj-text font-size="18x" line-height=1.5>
<mj-text font-size="18px" line-height="1.5">
{% if user %}<p>Dear {{ user.profile.name }},</p>{% endif %}
<p>
<strong>{{ callback_token }}</strong> is your code to
Expand Down
19 changes: 18 additions & 1 deletion cl8/users/templatetags/mjml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import logging

from django import template
from mjml import mjml2html

logger = logging.getLogger(__name__)
# Used for convenience to see the contents of a template
# before is passed as to convert from mjml to html for email
# logger.setLevel(logging.DEBUG)

register = template.Library()


Expand All @@ -10,7 +17,6 @@ def __init__(self, nodelist):

def render(self, context) -> str:
mjml_source = self.nodelist.render(context)
breakpoint()
return mjml_render(mjml_source)


Expand All @@ -35,4 +41,15 @@ def mjml(parser, token) -> MJMLRenderNode:


def mjml_render(mjml_source: str) -> str:
"""
Render the provided MJML template string, with template context
already added. Returns the html formatted for email clients.
"""
logger.debug(mjml_source)

# Tip: mjml2html does not give very helpful error messages.
# Paste the `mjml_source` string into a validator like the one
# below if is raising errors
# https://mjml.io/try-it-live/

return mjml2html(mjml_source)

0 comments on commit bb0965c

Please sign in to comment.