events.rst 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. .. _events:
  2. Events
  3. ======
  4. In order to extend FlaskBB you will need to connect your callbacks with
  5. events.
  6. .. admonition:: Additional events
  7. If you miss an event, feel free to open a new issue or create a pull
  8. request. The pull request should always contain a entry in this document
  9. with a small example.
  10. An event can be created by placing a :func:`~flask_plugins.emit_event`
  11. function at specific places in the code which then can modify the behavior
  12. of FlaskBB. The same thing applies for template events.
  13. Python Event:
  14. .. sourcecode:: python
  15. def foobar(data)
  16. somedata = "foobar"
  17. emit_event("your-newly-contributed-event", somedata)
  18. Template Event:
  19. .. sourcecode:: html+jinja
  20. {{ emit_event("your-newly-contributed-template-event") }}
  21. Python Events
  22. -------------
  23. None at the moment.
  24. Template Events
  25. ---------------
  26. Template events, which are used in forms, are usually rendered after the
  27. hidden CSRF token field and before an submit field.
  28. .. data:: before-first-navigation-element
  29. in ``templates/layout.html``
  30. This event inserts a navigation link **before** the **first** navigation
  31. element is rendered.
  32. .. sourcecode:: python
  33. def inject_navigation_element():
  34. return render_template("navigation_element_snippet.html")
  35. connect_event("before-first-navigation-element", inject_navigation_element)
  36. .. data:: after-last-navigation-element
  37. in ``templates/layout.html``
  38. This event inserts a navigation link **after** the **last** navigation
  39. element is rendered.
  40. .. sourcecode:: python
  41. def inject_navigation_element():
  42. return render_template("navigation_element_snippet.html")
  43. connect_event("after-last-navigation-element", inject_navigation_element)
  44. .. data:: before-registration-form
  45. in ``templates/auth/register.html``
  46. This event is emitted in the Registration form **before** the first
  47. input field but after the hidden CSRF token field.
  48. .. sourcecode:: python
  49. connect_event("before-registration-form", do_before_register_form)
  50. .. data:: after-registration-form
  51. in ``templates/auth/register.html``
  52. This event is emitted in the Registration form **after** the last
  53. input field but before the submit field.
  54. .. sourcecode:: python
  55. connect_event("after-registration-form", do_after_register_form)
  56. .. data:: before-update-user-details
  57. in ``templates/user/change_user_details.html``
  58. This event is emitted in the Change User Details form **before** an
  59. input field is rendered.
  60. .. sourcecode:: python
  61. connect_event("before-update-user-details", do_before_update_user_form)
  62. .. data:: after-update-user-details
  63. in ``templates/user/change_user_details.html``
  64. This event is emitted in the Change User Details form **after** the last
  65. input field has been rendered but before the submit field.
  66. .. sourcecode:: python
  67. connect_event("after-update-user-details", do_after_update_user_form)