No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Loader.py 1.4KB

1234567891011121314151617181920212223242526272829
  1. #-*- coding: utf-8 -*-
  2. import jinja2
  3. import settings_local
  4. class TemplateLoader(object):
  5. ## @brief Initializes a template loader
  6. #
  7. # @param search_path str : the base path from which the templates are searched. To use absolute paths, you can set
  8. # it to the root "/". By default, it will be the root of the project, defined in the
  9. # settings of the application
  10. # @param follow_links bool : indicates whether or not to follow the symbolic links (default: True)
  11. def __init__(self, search_path=settings_local.base_path, follow_links=True):
  12. self.search_path = search_path
  13. self.follow_links = follow_links
  14. ## @brief Renders a HTML content of a template
  15. #
  16. # @param template_file str : path to the template file (starting from the base path used to instanciate the
  17. # TemplateLoader)
  18. # @param template_vars dict : parameters to be used in the template
  19. # @return str. String containing the HTML output of the processed templated
  20. def render_to_html(self, template_file, template_vars):
  21. loader = jinja2.FileSystemLoader(searchpath=self.search_path, followlinks=self.follow_links)
  22. environment = jinja2.Environment(loader=loader)
  23. template = environment.get_template(template_file)
  24. return template.render(template_vars)