Extending Admin Dashboard UI
Spree Admin Dashboard allows you easily extend existing pages and screens with your own code, without any need to modify the core codebase. This allows you to easily inject your custom UI elements without compromising the integrity of the core codebase. Which in effect allows you to safely update your Spree installation to the latest version.
How it works
The entire system works on the basis of injection points which are declared throughout the admin dashboard and allows you to push your own code there. Each injection point is identified by a key, eg. body_end_partials
.
Let’s say you want to add a new footer to the admin dashboard. You’ll need to generate a template in your application:
-
Ensure you have the proper directory to store your templates:
-
Create a new partial template file (partial templates file names start with underscore)
-
Add your own code to the partial
-
Register your partial in
config/initializers/spree.rb
The key is the name of the injection point, eg.
body_end_partials
.Remember to use the correct path to your partial and skip the
_
prefix. -
Restart your web server and you should see your new footer.
Making further changes to the partial template will not require you to restart the web server. They will be picked up automatically.
Admin Dashboard injection points
Here’s a list of all places you can inject your custom code:
Layout
<head>
<head>
head_partials
Injects code into the <head>
tag
<body>
<body>
body_start_partials
Injects code into the <body>
tag, before the main content
</body>
</body>
body_end_partials
Injects code into the <body>
tag, after the main content
Dashboard
Analytics
Analytics
dashboard_analytics_partials
Injects code into the dashboard analytics section, eg.
Sidebar
Sidebar
Orders
Orders List Filters
Orders List Filters
orders_filters_partials
Variables
The ActionView::Helpers::FormBuilder object.
Injects code into the orders list filters, to add custom filters.
This partial has access to the f
variable, which is the form builder for the filters, eg.
q_number_cont
- The name of the filter field. For filtering we’re using ransack gem, so the name of the filter field is the name of the attribute we’re filtering by. Learn more about ransack search syntax.form-control
- A bootstrap class for styling the input field.data: { filters_target: :input }
- Needed for the Stimulus Filters controller to work.
Order Page Dropdown
Order Page Dropdown
order_page_dropdown_partials
Variables
The Spree::Order object.
Injects code into the order page dropdown. This partial has access to the order
variable.
To add an additional dropdown item, you can use the following code:
dropdown-item
is a bootstrap class for styling the dropdown itemtarget: "_blank"
is used to open the link in a new tab
Order Page Header
Order Page Header
order_page_header_partials
Variables
The Spree::Order object.
Injects code into the order page header.
To add an additional action button near the ...
button, you can use the following code:
Injects code into the order page header.
To add an additional action button near the ...
button, you can use the following code:
To add an inline alert to the order page, you can use the following code:
local_time
is a helper for displaying the time in the user’s timezone in a human readable format (based on the browser’s timezone).
Order Page Body
Order Page Body
order_page_body_partials
Variables
The Spree::Order object.
Injects code into the order page body. This partial has access to the order
variable.
To add a new section to the order page, you can use the following code:
Order Page Sidebar
Order Page Sidebar
Products
Products List Filters
Products List Filters
products_filters_partials
Variables
The ActionView::Helpers::FormBuilder object.
Injects code into the products list filters. This partial has access to the f
variable, which is the form builder for the filters.
To add a new filter field, you can use the following code:
q_name_cont
is the name of the filter field. For filtering we’re using ransack gem, so the name of the filter field is the name of the attribute we’re filtering by. Learn more about ransack search syntax.form-control
is a bootstrap class for styling the input field.data: { filters_target: :input }
is needed for the Stimulus Filters controller to work.
Products Page Dropdown
Products Page Dropdown
product_dropdown_partials
Injects code into the products page dropdown. This partial has access to the product
variable.
To add an additional dropdown item, you can use the following code:
Your code will be placed before the dropdown divider.
Products Page Form
Products Page Form
product_form_partials
Variables
The ActionView::Helpers::FormBuilder object.
The Spree::Product object.
Injects code into the product form. This partial has access to the f
variable, which is the form builder for the product form, and the product
variable.
To add a new section to the product form, you can use the following code:
The partial will be displayed for both new product form and edit product form.
If you want to display the partial only on the edit product form, you can use the following code:
And similarly for the new product form.
Products Page Sidebar
Products Page Sidebar
Shipping Methods
Shipping Methods Form
Shipping Methods Form
shipping_method_form_partials
Variables
The ActionView::Helpers::FormBuilder object.
The Spree::ShippingMethod object.
Injects code into the shipping method form. This partial has access to the f
variable, which is the form builder for the shipping method form, and the shipping_method
variable.
To add a new section to the shipping method form, you can use the following code:
Store Settings
Store Settings Form
Store Settings Form
store_form_partials
Variables
The ActionView::Helpers::FormBuilder object.
The Spree::Store object.
Injects code into the store settings form. This partial has access to the f
variable, which is the form builder for the store form, and the store
variable.
To add a new section to the store form, you can use the following code: