"""The one Jinja2 environment every router renders through. Each `api/*` module used to build its own `Jinja2Templates`, which meant a template global had to be declared five times or a page rendered by the wrong router would blow up on an undefined name. One instance, one place. """ from pathlib import Path from fastapi.templating import Jinja2Templates from imptune.services import websearch templates = Jinja2Templates(directory=str(Path(__file__).parent / "templates")) # Passed as the function, not its result: `WEB_SEARCH` is read per call, so a # test (or a config reload) that flips it takes effect without a restart. templates.env.globals["web_search_enabled"] = websearch.enabled