Theme Tutorial¶
Shopyo comes with a powerful built-in theming engine. This allows you to separate the visual presentation of your application from its logic, and switch between different designs on the fly.
This tutorial will guide you through understanding, using, and creating themes in Shopyo.
Concepts¶
Shopyo distinguishes between two types of themes:
Front Theme: The theme used for the public-facing side of your website (e.g., landing pages, blog posts, store front).
Back Theme: The theme used for the administration dashboard and internal tools.
Theme Location¶
Themes can live in two places:
App ``static/themes/`` directory – for project-local themes
Blueprint ``static/themes/`` directory – for themes bundled in a pip package (namespaced as
<blueprint>/<theme_name>)
Creating a Theme¶
Let’s create a new Front theme called ocean_blue.
Create the Directory: Navigate to
static/themes/front/and create a folder namedocean_blue.Add Metadata: Inside
ocean_blue, create a file namedinfo.json. This file tells Shopyo about your theme.{ "display_string": "Ocean Blue", "author": { "name": "Jane Doe", "website": "https://example.com", "mail": "jane@example.com" }, "version": "1.0.0", "description": "A calming blue theme for the store." }
Add Styles: Create a
styles.cssfile in the same directory. This will be the main entry point for your theme’s CSS.body { background-color: #e0f7fa; color: #01579b; font-family: sans-serif; } .navbar { background-color: #0277bd !important; }
Add Required Sections (see Theme Development Conventions for details): Create a
sections/directory withnav.html,footer.html,resources.html, anddrawer_head.html.
Using Themes in Templates¶
To make sure your templates load the CSS from the currently active theme, use the theme helper in your base template:
For the Back Theme (Admin):
<link rel="stylesheet" href="{{ shopyo_theme.get_active_back_theme_styles_url() }}">
For the Front Theme (Public):
<link rel="stylesheet" href="{{ shopyo_theme.get_active_front_theme_styles_url() }}">
Activating a Theme¶
Run your Shopyo application:
flask run --debug.Log in as an administrator.
Go to the Theme module (typically found in the dashboard sidebar).
You will see your new “Ocean Blue” theme listed under Front Themes.
Click the Activate button.
The page should reload, and if your templates are set up correctly, you will see your new blue background applied!
Advanced: Theme Assets¶
If your theme needs images or JavaScript files, simply place them inside
your theme folder (e.g., static/themes/front/ocean_blue/assets/).
You can reference them in your CSS relative to the CSS file:
.hero-banner {
background-image: url('assets/banner.jpg');
}
Or if you need to link to them from Jinja templates, you might need to construct the path manually or use a helper, but typically themes are self-contained via their CSS.