yireo / magento2-theme-by-route
Assign a specific theme to specific routes
Package info
github.com/yireo/Yireo_ThemeByRoute
Type:magento2-module
pkg:composer/yireo/magento2-theme-by-route
Requires
- php: >=8.2 <8.6
- ext-pcre: *
- magento/framework: ^103.0
- magento/module-backend: ^102.0
- magento/module-config: ^101.2
- magento/module-store: ^101.1
- magento/module-theme: ^101.1
- psr/log: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- ext-json: *
- phpunit/phpunit: ^10.5 || ^11.0 || ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Magento 2 module to allow a file app/etc/theme-by-route.json to determine which theme needs to be loaded for which route.
Installation
composer require yireo/magento2-theme-by-route bin/magento module:enable Yireo_ThemeByRoute
Configuration
Create a file app/etc/theme-by-route.json similar to the following:
{
"Loki/luma": [
"cms/index/index"
]
}
Now, the Loki/luma theme is applied to the homepage (cms/index/index), while all other pages keep the theme that is configured for the store.
Each entry in the list of pages is matched against the current request in three ways:
- Route name (an entry without a slash, like
checkoutorcustomer): applies to all pages of that route. - Full action name (like
cms/index/indexorcms_index_index): applies to a single controller action. Matching is case-insensitive. - URL path (like
about-usorcustomer/account/login): matched against the path of the URL, without the base URL, the store code and the query string.
If you want to control under which circumstances which theme is applied, there is an advanced syntax as well:
[
{
"scope_type": "website",
"scope_code": "base",
"theme": "Loki/luma",
"pages": [
"cms/index/index"
]
}
]
The scope_type is either website, group or store, and scope_code is the code of that website, store group or store view. All entries that match the current scope are combined. When multiple themes match the same request, the first theme in the file wins.
Notes
- After changing
app/etc/theme-by-route.json(or the Enabled setting under Stores > Configuration > Advanced > System > Yireo ThemeByRoute), flush the Full Page Cache:bin/magento cache:clean full_page. - Design changes (scheduled designs) and user-agent design exceptions are applied after this module and therefore take precedence.
- Make sure that the static content of every theme in the file is deployed.