Jinja Macro Example. Jinja is a general purpose template engine, it is not only used
Jinja is a general purpose template engine, it is not only used for HTML documents. A Jinja template doesn’t need to have a specific extension: . See Template Designer Documentation for a comprehensive guide to Jinja syntax and features. The Jinja sandbox can be used to render untrusted templates. For example, your code may have an intermediate step where users may use templates to define values that will then be passed to a traditional string environment. We also recommend using a virtual environment in order to isolate your project dependencies from other projects and the system. Jinja supports extensions that can add extra filters, tests, globals or even extend the parser. Flask sets up a Jinja environment and template loader for you, and provides functions to easily render templates from view functions. ¶ Jinja is a fast, expressive, extensible templating engine. Access to attributes, method calls, operators, mutating data structures, and string formatting can be intercepted and prohibited. Then the template is passed data to render the final document. Jinja uses a central object called the template Environment. HTML escaping wouldn’t make sense for any of these document types. This is useful if you are using Jinja outside the context of creating text files. Tips and Tricks This part of the documentation shows some tips and tricks for Jinja templates. The Flask web application framework, also maintained by Pallets, uses Jinja templates by default. The main motivation of extensions is to move often used code into a reusable class like adding support for internationalization. Jinja can generate any text-based format (HTML, XML, CSV, LaTeX, etc. . You can generate plain text, LaTeX, emails, CSS, JavaScript, configuration files, etc. Null-Default Fallback ¶ Jinja supports dynamic inheritance and does not distinguish between parent and child template as long as no extends tag is visited. html, . Jinja supports Python 3. xml, or any other extension is just fine. 7 and newer. ). Instances of this class are used to store the configuration and global objects, and are used to load templates from the file system or other locations. Special placeholders in the template allow writing code similar to Python syntax. ¶ Jinja is a fast, expressive, extensible templating engine. This is a brief guide on some of the differences between Jinja syntax and other template languages.