Selaa lähdekoodia

[#101] TemplateLoader is able to receive custom filters or apis

Roland Haroutiounian 9 vuotta sitten
vanhempi
commit
7f62685695
1 muutettua tiedostoa jossa 4 lisäystä ja 1 poistoa
  1. 4
    1
      Template/Loader.py

+ 4
- 1
Template/Loader.py Näytä tiedosto

@@ -22,8 +22,11 @@ class TemplateLoader(object):
22 22
     #                            TemplateLoader)
23 23
     # @param template_vars dict : parameters to be used in the template
24 24
     # @return str. String containing the HTML output of the processed templated
25
-    def render_to_html(self, template_file, template_vars):
25
+    def render_to_html(self, template_file, template_vars={}, template_extra={}):
26 26
         loader = jinja2.FileSystemLoader(searchpath=self.search_path, followlinks=self.follow_links)
27 27
         environment = jinja2.Environment(loader=loader)
28 28
         template = environment.get_template(template_file)
29
+        if template_extra is not None or template_extra != {}:
30
+            for extra in template_extra:
31
+                template.globals[extra[0]] = extra[1]
29 32
         return template.render(template_vars)

Loading…
Peruuta
Tallenna