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.
- Inherit parent themes CSS entrypoint files (theme.css, theme.scss) - default is true
- Inherit parent themes JS entrypoint files (theme.js) - default is true
- Inherit parent themes bootstrap files (bootstrap.js) - default is true
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, even an empty one.
| 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.
Unhashed files
Copy your files to web/static-unhashed instead to avoid hashing.
This means when you add this in a template:
It will result in this:
Theme static files referencing
To reference static files in CSS/SCSS files, add an alias in the theme build method:
| design/Vendor/ThemeName/Theme.php | |
|---|---|
Then use something like this in your style:
You could, of course, add an alias to the whole static directory of the theme like this:
| design/Vendor/ThemeName/Theme.php | |
|---|---|
And then use it like this:
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)
php bin/ama view:theme:build frontend --build-mode=build --build-all # (3)
php bin/ama view:theme:build backend --build-mode=build --build-all # (4)
- Build using the frontend area theme.
- Build using the backend area theme.
- Build all registered frontend themes.
- Build all registered backend themes.
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 (bootstrap.js) from all parent themes.
Default: true