You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -186,9 +213,70 @@ You can add more rules by extending the Validator class.
186
213
```
187
214
188
215
### Notes
216
+
189
217
- Use the `validate()` helper for a shortcut: `validate($data, $rules)`
190
218
- See the Validator class in `core/Support/Validator.php` for more details and to add custom rules.
191
219
220
+
## Dark/Light Mode Support
221
+
222
+
SproutPHP supports instant dark and light mode switching using PicoCSS's built-in color schemes. The framework provides an optional sun/moon icon button in the navbar to toggle the theme.
223
+
224
+
- PicoCSS automatically applies dark or light styles based on the `data-theme` attribute on `<html>`.
225
+
- The toggle button updates `data-theme` to `dark` or `light` and saves the preference in localStorage.
226
+
- No extra CSS is needed for the color scheme itself—PicoCSS handles all color changes.
- Clicking the icon toggles the theme and updates the icon instantly.
277
+
- The theme preference is saved in `localStorage`.
278
+
- PicoCSS automatically applies the correct color scheme.
279
+
192
280
## Using HTMX and PicoCSS
193
281
194
282
You do **not** need to install or include HTMX or PicoCSS yourself—they are already downloaded and loaded in your base template:
@@ -209,6 +297,7 @@ SproutPHP uses a **hybrid system** for making PHP helper functions available in
209
297
### Usage
210
298
211
299
1.**Add a helper to `helpers.php`:**
300
+
212
301
```php
213
302
// core/Support/helpers.php
214
303
if (!function_exists('my_custom_helper')) {
@@ -217,7 +306,9 @@ SproutPHP uses a **hybrid system** for making PHP helper functions available in
217
306
}
218
307
}
219
308
```
309
+
220
310
Now you can use it in Twig:
311
+
221
312
```twig
222
313
{{ my_custom_helper('hello') }}
223
314
```
@@ -231,13 +322,15 @@ SproutPHP uses a **hybrid system** for making PHP helper functions available in
231
322
```
232
323
233
324
### How it works
325
+
234
326
- All helpers in `helpers.php` are auto-registered.
235
327
- Any helpers listed in `twig_helpers` are also registered (even if not in `helpers.php`).
236
328
- If a helper exists in both, it is only registered once.
237
329
238
330
**This means most of the time, you just add your helper to `helpers.php` and it works in Twig!**
239
331
240
332
### Note on the `view()` Helper
333
+
241
334
- The `view()` helper now supports a third parameter `$return` (default: `false`).
242
335
- If `$return` is `true`, it returns the rendered string instead of echoing it. This is used by the generic fragment helper to inject fragments into layouts.
243
336
@@ -257,6 +350,7 @@ Route::get('/my-fragment', function () {
257
350
render_fragment_or_full('partials/my-fragment', $data); // uses layouts/base.twig by default
258
351
});
259
352
```
353
+
260
354
-**Best for most use cases.**
261
355
- Keeps your code DRY and consistent.
262
356
- Ensures direct URL access always returns a full page.
@@ -277,6 +371,7 @@ Route::get('/my-fragment', function () {
277
371
}
278
372
});
279
373
```
374
+
280
375
-**Use when you need custom logic per route.**
281
376
- Useful for advanced scenarios or when you want to handle fragments differently.
282
377
@@ -300,6 +395,7 @@ Sometimes you want a link to always trigger a full page reload (for example, you
300
395
```
301
396
302
397
**Best Practice:**
398
+
303
399
- Use these attributes for any link that should always reload the full page, such as your site home or links to external sites.
304
400
- This prevents issues where the page loses its CSS/JS context due to HTMX fragment swaps.
305
401
@@ -313,6 +409,7 @@ SproutPHP includes a built-in CORS middleware, registered globally by default bu
313
409
- By default, CORS is **disabled** for security. Enable only if you need cross-origin requests (e.g., for APIs or frontend apps).
314
410
315
411
**Example config/security.php:**
412
+
316
413
```php
317
414
'cors' => [
318
415
'enabled' => env('CORS_ENABLED', false),
@@ -323,6 +420,7 @@ SproutPHP includes a built-in CORS middleware, registered globally by default bu
323
420
```
324
421
325
422
**Security Note:**
423
+
326
424
- Only enable CORS for trusted origins in production. Use `*` for development only.
327
425
328
426
## CLI Reference
@@ -350,8 +448,8 @@ SproutPHP is a living, growing project—just like its name! Contributions, idea
350
448
SproutPHP includes a post-install script that lets you choose your preferred PicoCSS build right after running `composer install`.
351
449
352
450
### How it Works
353
-
- After installing dependencies, you'll be prompted to select a PicoCSS build:
354
-
0. Default Sprout Layout (Minimal PicoCSS) — just press Enter or choose 0 for the default
451
+
452
+
- After installing dependencies, you'll be prompted to select a PicoCSS build: 0. Default Sprout Layout (Minimal PicoCSS) — just press Enter or choose 0 for the default
355
453
1. Minimal (Standard)
356
454
2. Classless
357
455
3. Conditional
@@ -366,17 +464,19 @@ SproutPHP includes a post-install script that lets you choose your preferred Pic
366
464
- The script will download the latest PicoCSS file from the CDN and save it as `public/assets/css/sprout.min.css`.
| Toggle light/dark with JS | Conditional or Conditional + Color Theme |
475
+
| Full-width layout, no classes | Fluid Classless |
476
+
| Define your own classes | Color Palette Only |
378
477
379
478
### Changing PicoCSS Later
479
+
380
480
- You can re-run the post-install script at any time:
381
481
```bash
382
482
php core/Console/PostInstall.php
@@ -388,6 +488,7 @@ SproutPHP includes a post-install script that lets you choose your preferred Pic
388
488
- Or, manually download your preferred PicoCSS file from [jsdelivr PicoCSS CDN](https://cdn.jsdelivr.net/npm/@picocss/pico@latest/css/) and place it in `public/assets/css/sprout.min.css`.
389
489
390
490
### Advanced
491
+
391
492
- All PicoCSS builds and color themes are available. See the [PicoCSS documentation](https://picocss.com/docs/) for more details on each build type and theme.
392
493
393
494
## Production Build (bloom Command)
@@ -402,4 +503,3 @@ This will run the production build process (minifies, strips dev code, precompil
402
503
403
504
- The old `build` command is now replaced by `bloom` for clarity and branding.
404
505
- Use this command before deploying your app to production.
0 commit comments