Skip to content

Commit 07abb6d

Browse files
author
Sébastien HEYD
committed
feat(theme): add environment variable support for theme selection
- Add BOILERPLATE_THEME environment variable to control theme selection dynamically - Implement automatic theme validation with fallback to default theme - Update theme configuration to support environment-based theme switching - Document environment variable method as recommended approach for theme changes - Enhance documentation with complete setup instructions and validation details
1 parent 90c4d37 commit 07abb6d

File tree

3 files changed

+60
-10
lines changed

3 files changed

+60
-10
lines changed

docs/docs/8.x/configuration/theme.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ The `config/boilerplate/theme.php` file allows to define the backend theme param
66

77
```php
88
<?php
9-
$theme = include __DIR__.'/themes/default.php';
9+
// Selected theme
10+
$selectedTheme = env('BOILERPLATE_THEME', 'default');
11+
12+
// Check if theme exists
13+
$themePath = __DIR__.'/themes/'.$selectedTheme.'.php';
14+
if (!file_exists($themePath)) {
15+
$selectedTheme = 'default';
16+
$themePath = __DIR__.'/themes/default.php';
17+
}
18+
19+
$theme = include $themePath;
1020

1121
$theme += [
1222
'navbar' => [ // Additionnal views to append items to the navbar
@@ -24,7 +34,9 @@ return $theme;
2434

2535
## theme
2636

27-
Theme to use.
37+
Theme to use. You can change the theme by setting the `BOILERPLATE_THEME` environment variable in your `.env` file.
38+
39+
The system automatically validates that the specified theme file exists and falls back to the default theme if not found.
2840

2941
See [How to change theme](/howto/change-theme)
3042

docs/docs/8.x/howto/change_theme.md

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
# Change theme
22

3-
To change the theme, you must define it in the [`config/theme.php`](/configuration/theme) file.
3+
To change the theme, you can use the `BOILERPLATE_THEME` environment variable in your `.env` file or define it directly in the [`config/theme.php`](/configuration/theme) file.
44

5-
All you have to do is to include the theme file you want to use :
5+
## Method 1: Environment Variable (Recommended)
6+
7+
Add the theme name to your `.env` file:
8+
9+
```env
10+
BOILERPLATE_THEME=black
11+
```
12+
13+
## Method 2: Direct Configuration
14+
15+
You can also manually modify the theme in your `config/boilerplate/theme.php` file:
616

717
```php
8-
$theme = include __DIR__.'/themes/default.php';
18+
// Selected theme
19+
$selectedTheme = env('BOILERPLATE_THEME', 'red'); // Change default here
20+
21+
// Check if theme exists
22+
$themePath = __DIR__.'/themes/'.$selectedTheme.'.php';
23+
if (!file_exists($themePath)) {
24+
$selectedTheme = 'default';
25+
$themePath = __DIR__.'/themes/default.php';
26+
}
27+
28+
$theme = include $themePath;
929
```
1030

11-
> Available themes are `default`, `black`, `red`.
31+
> Available themes are `default`, `black`, `red`. The system automatically validates theme existence and falls back to default if the specified theme is not found.
1232
1333
<a :href="$withBase('/assets/img/logs_stats.png')" class="img-link"><img :src="$withBase('/assets/img/logs_stats.png')" style="max-width:100%;height:100px;margin-right:.5rem" /></a>
1434
<a :href="$withBase('/assets/img/theme_black.png')" class="img-link"><img :src="$withBase('/assets/img/theme_black.png')" style="max-width:100%;height:100px;margin-right:.5rem" /></a>
@@ -18,11 +38,19 @@ $theme = include __DIR__.'/themes/default.php';
1838

1939
## Create a new theme
2040

21-
You don't have to create a new theme, you can also edit the `default` theme. But it is recommanded to create a new theme, so you can add modifications without touching the default themes.
41+
You don't have to create a new theme, you can also edit the `default` theme. But it is recommended to create a new theme, so you can add modifications without touching the default themes.
42+
43+
To create a new theme:
2244

23-
To create a new theme, just copy the `default.php` file in the `config` folder to a new theme file.
45+
1. Copy the `default.php` file in the `config/boilerplate/themes/` folder to a new theme file (e.g., `custom.php`)
46+
2. Modify your new theme file as needed
47+
3. Set the `BOILERPLATE_THEME` environment variable to your new theme name:
48+
49+
```env
50+
BOILERPLATE_THEME=custom
51+
```
2452

25-
After that, just modify the theme included in `config/theme.php` by calling your new theme file.
53+
The system will automatically load your custom theme. If the theme file doesn't exist, it will fallback to the default theme.
2654

2755
---
2856

src/config/theme.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
<?php
22

3-
$theme = include __DIR__.'/themes/default.php';
3+
// Selected theme
4+
$selectedTheme = env('BOILERPLATE_THEME', 'default');
5+
6+
// Check if theme exists
7+
$themePath = __DIR__.'/themes/'.$selectedTheme.'.php';
8+
if (!file_exists($themePath)) {
9+
$selectedTheme = 'default';
10+
$themePath = __DIR__.'/themes/default.php';
11+
}
12+
13+
$theme = include $themePath;
414

515
$theme += [
616
'navbar' => [ // Additionnal views to append items to the navbar

0 commit comments

Comments
 (0)