jinja2.go 743 B

123456789101112131415161718192021222324252627282930313233343536
  1. package preload
  2. import "fmt"
  3. var (
  4. JINJA_PRELOAD_TEMPLATE = `{% set fruits = ['Apple'] %}
  5. {{ 'a' }}
  6. {% for fruit in fruits %}
  7. <li>{{ fruit }}</li>
  8. {% endfor %}
  9. {% if fruits|length > 1 %}
  10. 1
  11. {% endif %}
  12. {% for i in range(5) %}
  13. {% if i == 3 %}{{ i }}{% else %}{% endif %}
  14. {% endfor %}
  15. {% for i in range(3) %}
  16. {{ i + 1 }}
  17. {% endfor %}
  18. {% macro say_hello() %}a{{ 'b' }}{% endmacro %}
  19. {{ s }}{{ say_hello() }}`
  20. )
  21. func init() {
  22. SetupDependency("jinja2", "", fmt.Sprintf(`import jinja2
  23. def _jinja2_preload_():
  24. # prepare jinja2 environment, load template and render before to avoid sandbox issue
  25. template = jinja2.Template('''%s''')
  26. template.render(s='a')
  27. if __name__ == '__main__':
  28. _jinja2_preload_()
  29. `, JINJA_PRELOAD_TEMPLATE,
  30. ))
  31. }