.. _template_context: Template context ================ This page documents the variables that are available to custom templates for each of Datasette's core pages. See :ref:`customization_custom_templates` for how to provide your own templates. The variables documented here are a stable contract: custom templates that use them will continue to work across Datasette releases, up until the next major version (Datasette 2.0). Anything present in the template context but not documented on this page is not part of that contract and may change or be removed in any release. You can inspect the full context for any page by starting Datasette with ``--setting template_debug 1`` and adding ``?_context=1`` to the page URL. .. [[[cog from template_context_doc import template_context template_context(cog) .. ]]] Base context ------------ These variables are available on every page rendered by Datasette, including pages rendered by plugins that use :ref:`datasette.render_template() `. Plugins can add additional variables using the :ref:`plugin_hook_extra_template_vars` hook. ``request`` The current :ref:`Request object `, or None. Common properties include ``request.path``, ``request.args``, ``request.actor``, ``request.url_vars`` and ``request.host``. ``crumb_items`` Async function returning breadcrumb navigation items for the current page. Call it with ``request=request`` plus optional ``database=`` and ``table=`` arguments; it returns a list of ``{"href": url, "label": label}`` dictionaries. ``urls`` Object with methods for constructing URLs within Datasette. Common methods include ``urls.instance()``, ``urls.database(database)``, ``urls.table(database, table)``, ``urls.query(database, query)``, ``urls.row(database, table, row_path)`` and ``urls.static(path)`` - see :ref:`internals_datasette_urls`. ``actor`` The currently authenticated actor dictionary, or None. Actors usually include an ``id`` key and may include any other keys supplied by authentication plugins. ``menu_links`` Async function returning links for the Datasette application menu, including links added by plugins. Each item is a link dictionary with ``href`` and ``label`` keys. See :ref:`plugin_hook_menu_links`; for page action menus that can also include JavaScript-backed buttons, see :ref:`plugin_actions`. ``display_actor`` Function that accepts an actor dictionary and returns the display string used in the navigation menu. ``show_logout`` True if the logout link should be shown in the navigation menu ``zip`` Python's ``zip()`` builtin, made available to template logic ``body_scripts`` List of JavaScript snippets contributed by plugins using :ref:`plugin_hook_extra_body_script`. Each item is a dictionary with ``script`` containing JavaScript source and ``module`` indicating whether Datasette will wrap it in ``