From c7d145e016522dd6ee229d4d0b3ba79a7a8877c1 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 8 Jun 2020 12:06:05 -0700 Subject: [PATCH] Updated example for extra_template_vars hook, closes #816 --- docs/plugins.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/plugins.rst b/docs/plugins.rst index 56041d0c..6b1e60f2 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -689,14 +689,14 @@ Function that returns an awaitable function that returns a dictionary Datasette runs Jinja2 in `async mode `__, which means you can add awaitable functions to the template scope and they will be automatically awaited when they are rendered by the template. -Here's an example plugin that returns an authentication object from the ASGI scope: +Here's an example plugin that adds a ``"user_agent"`` variable to the template context containing the current request's User-Agent header: .. code-block:: python @hookimpl def extra_template_vars(request): return { - "auth": request.scope.get("auth") + "user_agent": request.headers.get("user-agent") } This example returns an awaitable function which adds a list of ``hidden_table_names`` to the context: