-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrender.py
More file actions
29 lines (22 loc) · 896 Bytes
/
Copy pathrender.py
File metadata and controls
29 lines (22 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Template renderer for Jinja2 email templates.
This script loads JSON data and renders it using a Jinja2 template,
saving the output as an HTML file for preview.
"""
import json
import os
from jinja2 import Environment, FileSystemLoader
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# Load user data
with open(os.path.join(BASE_DIR, "templates/data.json"), "r", encoding="utf-8") as f:
data = json.load(f)
# Jinja2 setup
env = Environment(loader=FileSystemLoader(os.path.join(BASE_DIR, "templates")), autoescape=True)
template = env.get_template("template.j2")
# Render with data
rendered_html = template.render(data)
# Save rendered email for preview
output_file = os.path.join(BASE_DIR, "rendered_email.html")
with open(output_file, "w", encoding="utf-8") as f:
f.write(rendered_html)
print(f"✅ Email template rendered! Open {output_file} in a browser to preview.")