feat: make context optional when calling render_template

This commit is contained in:
Sagar Vora 2022-12-07 13:32:38 +05:30
parent f2e1dbe7eb
commit 10695d3d49
2 changed files with 5 additions and 2 deletions

View file

@ -77,4 +77,4 @@ class TestSafeExec(FrappeTestCase):
self.assertRaises(SyntaxError, safe_exec, """frappe.msgprint("Hello")""", unsafe_global)
def test_frappe_dict_in_jinja(self):
frappe.render_template("{% set my_dict = _dict() %} {{- my_dict.works -}}", {})
frappe.render_template("{% set my_dict = _dict() %} {{- my_dict.works -}}")

View file

@ -60,7 +60,7 @@ def validate_template(html):
frappe.throw(frappe._("Syntax error in template"))
def render_template(template, context, is_path=None, safe_render=True):
def render_template(template, context=None, is_path=None, safe_render=True):
"""Render a template using Jinja
:param template: path or HTML containing the jinja template
@ -76,6 +76,9 @@ def render_template(template, context, is_path=None, safe_render=True):
if not template:
return ""
if not context:
context = {}
if is_path or guess_is_path(template):
return get_jenv().get_template(template).render(context)
else: