|
1 | | -# codeigniter4-assets |
| 1 | +# Tatter\Assets |
2 | 2 | Lightweight asset loader for CodeIgniter 4 |
| 3 | + |
| 4 | +## Features |
| 5 | + |
| 6 | +Provides out-of-the-box asset loading for CSS and JavaScript files |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +Install easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities |
| 11 | +and always be up-to-date: |
| 12 | +`> composer require tatter/assets` |
| 13 | + |
| 14 | +Or, install manually by downloading the source files and copying them into CodeIgniter 4's |
| 15 | +app/ same subdirectories. |
| 16 | + |
| 17 | +## Configuration (optional) |
| 18 | + |
| 19 | +The library's default behavior can be overridden or augment by its config file. Copy |
| 20 | +src/Config/Assets.php.example to app/Config/Assets.php and follow the instructions in the |
| 21 | +comments. If no config file is found the library will use its defaults. |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +If installed correctly CodeIgniter 4 will detect and autoload the library, helper, and |
| 26 | +(optional) config. Initialize the helper before using its functions: |
| 27 | +`helper("tatter\assets");` |
| 28 | + |
| 29 | +Then call the helper functions `css()` and `js()` to output the appropriate assets. |
| 30 | + |
| 31 | +## Structure |
| 32 | + |
| 33 | +The library searches the assets directory (default: public/assets) for files matching the |
| 34 | +current route, loading them in a cascading fashion for each route segment. |
| 35 | +**Example:** https://example.com/users/view/12 |
| 36 | + |
| 37 | +The library will first load any root assets (public/assets/*.css *.js), then assets in |
| 38 | +the users subfolder (public/assets/users/) then view subfolder, then 12 subfolder. Any |
| 39 | +missing or invalid folders are ignored. |
| 40 | + |
| 41 | +Additional assets may be loaded from the config variable $routes - this is particularly |
| 42 | +helpful for including pre-bundled libraries. |
| 43 | +**Example:** |
| 44 | +``` |
| 45 | +public $routes = [ |
| 46 | + "" => ["bootstrap/dist/css/bootstrap.min.css", "bootstrap/dist/js/bootstrap.bundle.min.js"] |
| 47 | +]; |
| 48 | +``` |
| 49 | + |
| 50 | +This tells the library to load Bootstrap for every route ("") without having to move it |
| 51 | +from its pre-bundled subdirectory. |
0 commit comments