Alex Ramalho
Alex Ramalho

Reputation: 416

Is it possible to add a Button to a Wagtail Settings page?

I am trying to customize a settings page so it has a button that I will assign to a certain action. (Let's assume for now I just want to log something into the console).

Ideally it would be of something like this:

@register_setting
class ActionTriggeringSetting(BaseSetting):
    button = models.ButtonField(
        action=myLoggingFunc,
        help_text='Click here to log "Hello World" to the console'
    )

I tried looking into the site settings but found nothing really helpful there.

Does anybody know if something of the sort exists?

Thank you

Upvotes: 2

Views: 1101

Answers (1)

Steve Jalim
Steve Jalim

Reputation: 12195

Depending on where in the admin UI you want you button to be, there is a way using the register-admin-menu-item or register-settings-menu-item Wagtail hook

See: https://docs.wagtail.io/en/v2.10.1/reference/hooks.html#register-admin-menu-item

and

https://docs.wagtail.io/en/v2.10.1/reference/hooks.html#register-settings-menu-item

The approaches above will add a button to the Wagtail Admin menu or the settings submenu, respectively. Clicking on the button will trigger a custom view that you also need to add - this is also loosely covered in the linked docs.

Upvotes: 2

Related Questions