ActionBar is an auxiliary UI plug-in for QOR Admin. It generates a small bar on the top of frontend pages. The bar contains:
- Switcher of
Preview
andEdit
mode, - Login/Logout links,
- Additional links according to QOR Admin configuration.
Register ActionBar to QOR Admin
ActionBar = action_bar.New(Admin)
Then render ActionBar in the view, usually we put it in the view context.
viewCtx["ActionBarTag"] = admin.ActionBar.Render(ctx.Writer, ctx.Request)
// In the template
{{.Result.ActionBarTag}}
Add link to ActionBar
ActionBar has a RegisterAction
function to do so. Here's an example that adds admin link to ActionBar.
ActionBar.RegisterAction(&action_bar.Action{Name: "Admin Dashboard", Link: "/admin"})
Imagine the administrator of a EC site could edit a product detail in the shopping page rather than edit it in the back-end CMS. The shopping page editing could help the administrator to have a better operation experience. We have integrated this feature to ActionBar. The setup is easy.
First, register view functions. The example uses Render to render the template. So we register functions by Render.RegisterFuncMap
. The admin.ActionBar
in the example is an instance of QOR Admin.
for key, value := range admin.ActionBar.FuncMap(ctx.Writer, ctx.Request) {
Render.RegisterFuncMap(key, value)
}
Then render the edit button in the template.
// Assume this is in the product show page
{{ render_edit_button .Product }}
Then you will see a Edit
button in the product show page and the administrator could edit product's info in the front-end directly.
Online Demo, you will see a bar at the top of homepage after logged in as an administrator.
Released under the MIT License.