From 4ce2888e79d4fdd5a6d5c4f949b70abac6f59e53 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 14 Jun 2026 15:58:37 -0700 Subject: [PATCH] Support for + {% else %} + {{ link.label }} + {% if link.description %} + {{ link.description }} + {% endif %} + {% endif %} {% endfor %} -{% endif %} \ No newline at end of file +{% endif %} diff --git a/docs/custom_templates.rst b/docs/custom_templates.rst index aa82a536..8851a841 100644 --- a/docs/custom_templates.rst +++ b/docs/custom_templates.rst @@ -288,6 +288,14 @@ element that wraps the HTML for that row. Datasette uses this attribute to find the element to remove after a delete, or replace after an edit. Any edit or delete controls should be rendered inside that same element. +The ``_action_menu.html`` template renders the action menus used by database, +table, query and row pages. Plugin-provided actions can be link dictionaries +with ``href`` and ``label`` keys, or button dictionaries using ``{"type": +"button", "label": "...", "attrs": {...}}`` for JavaScript-backed interactions. +Both shapes can include an optional ``description`` key. Custom +``_action_menu.html`` templates should preserve support for both link and button +action items. + .. _custom_pages: Custom pages diff --git a/docs/plugin_hooks.rst b/docs/plugin_hooks.rst index 7ae52a68..d2f87e27 100644 --- a/docs/plugin_hooks.rst +++ b/docs/plugin_hooks.rst @@ -1909,7 +1909,80 @@ Action hooks Action hooks can be used to add items to the action menus that appear at the top of different pages within Datasette. Unlike :ref:`menu_links() `, actions which are displayed on every page, actions should only be relevant to the page the user is currently viewing. -Each of these hooks should return return a list of ``{"href": "...", "label": "..."}`` menu items, with optional ``"description": "..."`` keys describing each action in more detail. +Each of these hooks should return a list of menu items, with optional ``"description": "..."`` keys describing each action in more detail. + +The most common action item is a link to another page: + +.. code-block:: python + + { + "href": datasette.urls.path("/-/custom-action"), + "label": "Custom action", + "description": "Run this action on a separate page.", + } + +Plugins can also return button actions for JavaScript-backed interactions: + +.. code-block:: python + + { + "type": "button", + "label": "Open custom dialog", + "description": "Show a dialog without leaving this page.", + "attrs": { + "aria-label": "Open custom dialog", + "data-plugin-action": "open-custom-dialog", + }, + } + +These are rendered as ``