Skip to content

Commit

Permalink
Updated example for extra_template_vars hook, closes #816
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 8, 2020
1 parent 040fc05 commit c7d145e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -689,14 +689,14 @@ Function that returns an awaitable function that returns a dictionary

Datasette runs Jinja2 in `async mode <https://jinja.palletsprojects.com/en/2.10.x/api/#async-support>`__, 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:
Expand Down

0 comments on commit c7d145e

Please sign in to comment.