Themes
Themes include layouts, templates, styles, frontend code and translations (i18n).
By default, the frontend area uses the Lux theme, while the backend area uses the Hadron theme.
A different theme can be used for both areas, although using Hadron for the backend area is recommended.
Themes support multiple inheritance of layouts and templates. Meaning if a theme has a parent theme defined and a layout or template is missing, it will be loaded from the parent theme or the parent's parent etc.
Note
Both Lux and Hadron use Bootstrap 5. If you don't want to depend on Bootstrap and/or you're working on a fully custom design,
you may not want to inherit such a theme. You can always build a standalone theme without a parent.
Create a theme
Theme file
- Theme name.
- Theme area.
- Add imports to Vite build file.
- Add Vite aliases.
- Add Vite plugins.
- Specify a parent theme.
Auto imports
These files will be automatically imported if found in the theme directory:
theme.tsortheme.jstheme.scssortheme.css
Note
To use only templates and layouts of a parent theme without including its CSS and JS, you can set the --inherit-entry-points to 0 when running the build command.
Bootstrap file
The bootstrap file must exist and return a function.
| design/Vendor/ThemeName/bootstrap.js | |
|---|---|
Stylesheets
The email and print stylesheets must exist under the theme's root folder:
web/css/print.css
web/css/email.css
These will be included when creating PDF content or email content.
Preprocessing
The theme build preprocessing will generate a new theme bootstrap file,
where it includes all auto imports, bootstraps each application module and finally
calls the bootstrap code from design/Vendor/ThemeName/bootstrap.js.
This file then becomes the input in the Vite build configuration.
Application module aliases
All aliases should automatically be resolved and created in Vite configuration and jsconfig/tsconfig.json files.
So in your code you can just import using aliases, like so:
import {baseStore} from "@AmarantFramework/app/store/store";
import {confirmation} from "@AmarantUi/js/notifier";
import {t} from "@AmarantUi/js/i18n";
Static files
A theme can have static files that are copied to the build directory. They are automatically hashed and resolved when used from a template.
This means you can add this in a template:
Which will result in something like this:
<img class="logo" src="/static/assets/themes/Amarant_Lux/page/logo-1671533e071292aa2e3e0a9c6a3959c9.png" alt="logo"/>
If a subdirectory web/static exists in your theme, all files will be automatically copied to the build
directory.
Note
Static files are not copied in development mode. You have to make a production build for that to happen.
Build
Development mode with hot reload
- Build using the frontend area theme.
- Build using the backend area theme.
Production
php bin/ama view:theme:build frontend --build-mode=build # (1)
php bin/ama view:theme:build backend --build-mode=build # (2)
- Build using the frontend area theme.
- Build using the backend area theme.
Command line options
--theme-name
Optionally specify a theme you want to build/develop. Default theme for an area will be used if no theme name is specified.
Default: Current area theme
--inherit-entry-points
Inherit entrypoints (theme.js/theme.ts, theme.css/theme.scss) from all parent themes.
Default: true