maizzle / framework

Quickly build HTML emails with Tailwind CSS.
https://maizzle.com
MIT License
1.21k stars 48 forks source link

Integrating Jinja2 Templates (server-side rendering) with Maizzle: Compatibility and Customization Concerns #1163

Closed NFeruch closed 7 months ago

NFeruch commented 7 months ago

I currently have an HTML email template that I'm using as part of a piece of software that I'm building, and I've templatized it using Jinja2 in Python. The way double curly braces {{ ... }} work in Maizzle, works the exact same way for Jinja. I just pass in a dictionary of the data that I want to fill in the template, and access parts of that dictionary within the HTML itself.

For instance, within the HTML template, I'll have something like

# in python...
data = {
  'title': 'blah',
  'attrs': ['one', 'two']
}
template = render_template(data)

# and within the HTML itself
<div> {{ attrs[0] }} </div>

The thing I want to make sure of about Maizzle, before I get too deep into it, is:

Can I integrate Jinja2 expression fields (double curly braces) into my Maizzle project, and have Maizzle ignore them and leave them as is? Same thing for for-loops and if-statements.

I already have a finished template that I paid a contractor to build, but they used bootstrap email (which I don't know) so it's essentially impossible for me to change it or add new sections. I DO know tailwindcss, so Maizzle is theoretically perfect, as it would mean that I can actually work on the template itself (I'm a data engineer, so most web dev things are out of my wheelhouse).

Ignoring certain {{ ... }} and {% ... %} fields would be a hard requirement for me to use Maizzle unfortunately, as within my template, there are many fields that I fill in with Jinja2 in my python script. It would aid my development cycle if I could work directly in tailwind when iterating on the template, but it would defeat the purpose if I had to re-add the Jinja2 expression fields every time I built the new template.

As I'm typing this out, I realize that templates in Maizzle have front matter, which could theoretically mean I can still templatize the values, but the data that I pass in is a very nested dictionary. Jinja2 has support for loops and if-statements and accessing elements of a list or dictionary, which I don't think Maizzle does.

Any thoughts are appreciated, and please let me know if I need to clarify anything!

cossssmin commented 7 months ago

Yup, it’s possible to ignore the expressions, see the docs:

https://maizzle.com/docs/expressions#ignoring