Templates — Aquilia Documentation
Comprehensive guide and documentation for Templates in the Aquilia framework. View API reference, examples, and implementation patterns.
Advanced / Templates Template Engine Overview AquilaTemplates is an async-native rendering engine built on top of Jinja2. It features sandboxed script execution, module-aware namespace loaders, precompiled bytecode caching, and auto-populated request/session contexts. System Integration & Registration Configure templates at the workspace level and organize directories within module structures. 1. Workspace Integration Register templates inside workspace.py using TemplatesIntegration : from aquilia.workspace import Workspace from aquilia.integrations import TemplatesIntegration workspace = ( Workspace("myapp") .integrate(TemplatesIntegration( search_paths=["templates", "shared_templates"], cache="memory", sandbox=True, sandbox_policy="strict" )) ) 2. Manifest Auto-Discovery & Layout By default, templates placed inside modules under the templates/ folder are auto-discovered. You can also customize search paths inside module.aq: } Engine Architecture , , , ].map((item, i) => ( ))} Rendering in Controllers Access the template system either through controller helper methods or by direct invocation of the injected TemplateEngine : from aquilia import Controller, Get, Inject from aquilia.templates import TemplateEngine class WebController(Controller): @Inject() def __init__(self, templates: TemplateEngine): self.templates = templates @Get("/") async def index(self, ctx): # 1. Convenient controller render helper (returns Response) return await self.render("index.html", , request_ctx=ctx) @Get("/profile") async def profile(self, ctx): # 2. Render directly to string via TemplateEngine html = await self.templates.render( "profile.html", , request_ctx=ctx ) return ctx.html(html) @Get("/dashboard") async def dashboard(self, ctx): # 3. Direct response generation via TemplateEngine return await self.templates.render_to_response( "dashboard.html", , status=200, request_ctx=ctx ) Auto-Injected Context Variables When rendering templates with request_ctx provided, the environment automatically attaches standard context helpers and objects: , , , , , , ].map((item, i) => ( ))} Adapters TemplateEngine )
Go to Homepage