Template Overview
Framefox uses Jinja2 as its templating engine, providing a powerful and familiar way to create dynamic HTML views. The template system is integrated directly into the framework’s MVC architecture, making it easy to render views from your controllers.Jinja2 Templating Engine
Jinja2 is a modern and designer-friendly templating language for Python. It provides:- Template inheritance with
{% extends %}and{% block %} - Control structures like loops and conditionals
- Filters for data transformation
- Template inclusion for reusable components
- Auto-escaping for XSS prevention
The render() Method
Controllers inherit fromAbstractController and use the render() method to return HTML responses:
Method Signature
Template Locations
Framefox looks for templates in multiple directories:1. User Template Directory
Your application templates are stored in thetemplates/ directory (configurable via settings):
2. Framework Template Directory
Framefox includes built-in templates for error pages and debug views located inframefox/core/templates/views/.
Template Resolution
The template loader searches directories in order:- User templates directory (your application)
- Framework templates directory (built-in views)
Basic Template Example
Context Variables
The context dictionary passed torender() becomes available as variables in your template:
Auto-Injected Variables
Framefox automatically injects certain variables into all templates:request- The current HTTP request objectcurrent_user- The authenticated user (if any)
Template Configuration
Configure template settings in yourconfig/settings.yaml:
Performance
Framefox’s template system includes:- Automatic template caching in Jinja2
- Built-in profiling to measure render times
- Memory tracking for template rendering
- Strict undefined variables to catch errors early
Next Steps
- Learn about built-in template functions
- Explore template inheritance
- Understand static asset handling