From d1b16309531e945439dfc061a5d9460f10410049 Mon Sep 17 00:00:00 2001 From: David Martin Date: Wed, 10 Mar 2021 14:25:57 +0100 Subject: [PATCH] Added Custom Parameters section to docs --- docs/index.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/index.rst b/docs/index.rst index cd4e43a..fd2f096 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -249,6 +249,28 @@ You do have to register the entire class with flask-menu at runtime however. MyEndpoint.register(bp) register_flaskview(bp, MyEndpoint) +.. _custom_parametters: + +Custom Parameters +================= + +If you want to register a menu option with a custom url parameter (for example, for +url's that have an optional parameter) you can use the `endpoint_arguments_constructor` +to achieve this. + +Here is an example: + +.. code-block:: python + + @bp_account.route('/list', defaults={'disabled': False}) + @bp_account.route('/list/') + @register_menu(bp_social, '.account.list', 'Social networks') + @register_menu(bp_social, '.account.list', 'Social networks (Disabled)', endpoint_arguments_constructor=lambda: {'disabled': True}) + def list(disabled): + pass + +This will register the same menu but with an optional URL parametter set to True. + .. _api: API