Template Hooks

Note

Template hooks, which are used in forms, are usually rendered after the hidden CSRF token field and before an submit field.

flaskbb.plugins.spec.flaskbb_tpl_navigation_before()[source]

Hook for registering additional navigation items.

in templates/layout.html.

flaskbb.plugins.spec.flaskbb_tpl_navigation_after()[source]

Hook for registering additional navigation items.

in templates/layout.html.

flaskbb.plugins.spec.flaskbb_tpl_user_nav_loggedin_before()[source]

Hook for registering additional user navigational items which are only shown when a user is logged in.

in templates/layout.html.

flaskbb.plugins.spec.flaskbb_tpl_user_nav_loggedin_after()[source]

Hook for registering additional user navigational items which are only shown when a user is logged in.

in templates/layout.html.

flaskbb.plugins.spec.flaskbb_tpl_form_registration_before(form)[source]

This hook is emitted in the Registration form before the first input field but after the hidden CSRF token field.

in templates/auth/register.html.

Parameters:form – The form object.
flaskbb.plugins.spec.flaskbb_tpl_form_registration_after(form)[source]

This hook is emitted in the Registration form after the last input field but before the submit field.

in templates/auth/register.html.

Parameters:form – The form object.
flaskbb.plugins.spec.flaskbb_tpl_form_user_details_before(form)[source]

This hook is emitted in the Change User Details form before an input field is rendered.

in templates/user/change_user_details.html.

Parameters:form – The form object.
flaskbb.plugins.spec.flaskbb_tpl_form_user_details_after(form)[source]

This hook is emitted in the Change User Details form after the last input field has been rendered but before the submit field.

in templates/user/change_user_details.html.

Parameters:form – The form object.
flaskbb.plugins.spec.flaskbb_tpl_form_new_post_before(form)[source]

Hook for inserting a new form field before the first field is rendered.

For example:

@impl
def flaskbb_tpl_form_new_post_after(form):
    return render_template_string(
        """
        <div class="form-group">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <label>{{ form.example.label.text }}</label>

                {{ form.example(class="form-control",
                                placeholder=form.example.label.text) }}

                {%- for error in form.example.errors -%}
                <span class="help-block">{{error}}</span>
                {%- endfor -%}
            </div>
        </div>
        """

in templates/forum/new_post.html

Parameters:form – The form object.
flaskbb.plugins.spec.flaskbb_tpl_form_new_post_after(form)[source]

Hook for inserting a new form field after the last field is rendered (but before the submit field).

in templates/forum/new_post.html

Parameters:form – The form object.
flaskbb.plugins.spec.flaskbb_tpl_form_new_topic_before(form)[source]

Hook for inserting a new form field before the first field is rendered (but before the CSRF token).

in templates/forum/new_topic.html

Parameters:form – The form object.
flaskbb.plugins.spec.flaskbb_tpl_form_new_topic_after(form)[source]

Hook for inserting a new form field after the last field is rendered (but before the submit button).

in templates/forum/new_topic.html :param form: The form object.

flaskbb.plugins.spec.flaskbb_tpl_profile_settings_menu(user)[source]

This hook is emitted on the user settings page in order to populate the side bar menu. Implementations of this hook should return a list of tuples that are view name and display text. The display text will be provided to the translation service so it is unnecessary to supply translated text.

A plugin can declare a new block by setting the view to None. If this is done, consider marking the hook implementation with trylast=True to avoid capturing plugins that do not create new blocks.

For example:

@impl(trylast=True)
def flaskbb_tpl_profile_settings_menu():
    return [
        (None, 'Account Settings'),
        ('user.settings', 'General Settings'),
        ('user.change_user_details', 'Change User Details'),
        ('user.change_email', 'Change E-Mail Address'),
        ('user.change_password', 'Change Password')
    ]

Hookwrappers for this spec should not be registered as FlaskBB supplies its own hookwrapper to flatten all the lists into a single list.

in templates/user/settings_layout.html

Changed in version 2.1.0: The user param. Typically this will be the current user but might not always be the current user.

Parameters:user – The user the settings menu is being rendered for.
flaskbb.plugins.spec.flaskbb_tpl_profile_sidebar_stats(user)[source]

This hook is emitted on the users profile page below the standard information. For example, it can be used to add additional items such as a link to the profile.

in templates/user/profile_layout.html

Parameters:user – The user object for whom the profile is currently visited.

This hook is emitted on the user profile page in order to populate the sidebar menu. Implementations of this hook should return an iterable of NavigationItem instances:

@impl
def flaskbb_tpl_profile_sidebar_links(user):
    return [
        NavigationLink(
            endpoint="user.profile",
            name=_("Overview"),
            icon="fa fa-home",
            urlforkwargs={"username": user.username},
        ),
        NavigationLink(
            endpoint="user.view_all_topics",
            name=_("Topics"),
            icon="fa fa-comments",
            urlforkwargs={"username": user.username},
        ),
        NavigationLink(
            endpoint="user.view_all_posts",
            name=_("Posts"),
            icon="fa fa-comment",
            urlforkwargs={"username": user.username},
        ),
    ]

Warning

Hookwrappers for this spec should not be registered as FlaskBB registers its own hook wrapper to flatten all the results into a single list.

New in version 2.1.

Parameters:user – The user the profile page belongs to.
flaskbb.plugins.spec.flaskbb_tpl_post_author_info_before(user, post)[source]

This hook is emitted before the information about the author of a post is displayed (but after the username).

in templates/forum/topic.html

Parameters:
  • user – The user object of the post’s author.
  • post – The post object.
flaskbb.plugins.spec.flaskbb_tpl_post_author_info_after(user, post)[source]

This hook is emitted after the information about the author of a post is displayed (but after the username).

in templates/forum/topic.html

Parameters:
  • user – The user object of the post’s author.
  • post – The post object.
flaskbb.plugins.spec.flaskbb_tpl_post_content_before(post)[source]

Hook to do some stuff before the post content is rendered.

in templates/forum/topic.html

Parameters:post – The current post object.
flaskbb.plugins.spec.flaskbb_tpl_post_content_after(post)[source]

Hook to do some stuff after the post content is rendered.

in templates/forum/topic.html

Parameters:post – The current post object.
flaskbb.plugins.spec.flaskbb_tpl_post_menu_before(post)[source]

Hook for inserting a new item at the beginning of the post menu.

in templates/forum/topic.html

Parameters:post – The current post object.
flaskbb.plugins.spec.flaskbb_tpl_post_menu_after(post)[source]

Hook for inserting a new item at the end of the post menu.

in templates/forum/topic.html

Parameters:post – The current post object.
flaskbb.plugins.spec.flaskbb_tpl_topic_controls(topic)[source]

Hook for inserting additional topic moderation controls.

in templates/forum/topic_controls.html

Parameters:topic – The current topic object.
flaskbb.plugins.spec.flaskbb_tpl_admin_settings_menu(user)[source]

This hook is emitted in the admin panel and used to add additional navigation links to the admin menu.

Implementations of this hook should return a list of tuples that are view name, display text and optionally an icon. The display text will be provided to the translation service so it is unnecessary to supply translated text.

For example:

@impl(trylast=True)
def flaskbb_tpl_admin_settings_menu():
    # only add this item if the user is an admin
    if Permission(IsAdmin, identity=current_user):
        return [
            ("myplugin.foobar", "Foobar", "fa fa-foobar")
        ]

Hookwrappers for this spec should not be registered as FlaskBB supplies its own hookwrapper to flatten all the lists into a single list.

in templates/management/management_layout.html

Parameters:user – The current user object.
flaskbb.plugins.spec.flaskbb_tpl_admin_settings_sidebar(user)[source]

This hook is emitted in the admin panels setting tab and used to add additional navigation links to the sidebar settings menu.

Implementations of this hook should return a list of tuples that are view name and display text. The display text will be provided to the translation service so it is unnecessary to supply translated text.

For example:

@impl(trylast=True)
def flaskbb_tpl_admin_settings_menu():
    return [
        ("myplugin.foobar", "Foobar")
    ]

Only admins can view the Settings tab.

Hookwrappers for this spec should not be registered as FlaskBB supplies its own hookwrapper to flatten all the lists into a single list.

in templates/management/settings.html

Parameters:user – The current user object.