Skip to content

Commit b969f26

Browse files
Add documentation for page_config_hook (#469)
* Add documentation for `page_config_hook` * tweaks * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3be3f00 commit b969f26

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/source/api/handlers.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,32 @@ Module: :mod:`jupyterlab_server.handlers`
1515
.. autoclass:: LabHandler
1616
:members:
1717

18+
.. rubric:: Page config hook
19+
20+
``page_config_hook`` is an optional callable you can provide via the Jupyter Server web application settings to customize the page configuration before it is rendered.
21+
22+
- Where: ``web_app.settings['page_config_hook']``
23+
- Signature: ``callable(handler, page_config) -> dict``
24+
- ``handler``: the active ``LabHandler`` instance
25+
- ``page_config``: a dict containing the current page configuration
26+
- Return: the updated page configuration dict.
27+
28+
Example (in a server extension ``load_jupyter_server_extension`` or ``_load_jupyter_server_extension``):
29+
30+
.. code-block:: python
31+
32+
def my_page_config_hook(handler, page_config: dict) -> dict:
33+
page_config.setdefault("extraKeys", {})
34+
page_config["extraKeys"]["hello"] = "world"
35+
return page_config
36+
37+
38+
def load_jupyter_server_extension(serverapp):
39+
web_app = serverapp.web_app
40+
web_app.settings["page_config_hook"] = my_page_config_hook
41+
42+
With this hook set, JupyterLab Server will call it during page configuration assembly, letting you inject or tweak values prior to rendering the index page.
43+
1844
.. autofunction:: add_handlers
1945

2046
.. autofunction:: is_url

0 commit comments

Comments
 (0)