|
| 1 | +# Theme System Modules |
| 2 | + |
| 3 | +A theme system module is a collection of customizations using the [visual](visual-theme-system.md) and [logical](logical-theme-system.md) theme systems, provided along with some metadata, that can be installed alongside other modules within a theme. They can effectively be thought of as "plugins" or "extensions" that can be applied in addition to any customizations in the active theme. |
| 4 | + |
| 5 | +### Module Location |
| 6 | + |
| 7 | +Modules are contained within a folder themselves, which should be located inside a `modules` folder within a [BookStack theme folder](visual-theme-system.md#getting-started). |
| 8 | +As an example, starting from the `themes/` top-level folder of a BookStack instance: |
| 9 | + |
| 10 | +```txt |
| 11 | +themes |
| 12 | +└── my-theme |
| 13 | + └── modules |
| 14 | + ├── module-a |
| 15 | + │ └── bookstack-module.json |
| 16 | + └── module-b |
| 17 | + └── bookstack-module.json |
| 18 | +``` |
| 19 | + |
| 20 | +### Module Format |
| 21 | + |
| 22 | +A module exists as a folder in the location [as detailed above](#module-location). |
| 23 | +The content within the module folder should then follow this format: |
| 24 | + |
| 25 | +- `bookstack-module.json` - REQUIRED - A JSON file containing [the metadata](#module-json-metadata) for the module. |
| 26 | +- `functions.php` - OPTIONAL - A PHP file containing code for the [logical theme system](logical-theme-system.md). |
| 27 | +- `icons/` - OPTIONAL - A folder containing any icons to use as per [the visual theme system](visual-theme-system.md#customizing-icons). |
| 28 | +- `lang/` - OPTIONAL - A folder containing any language files to use as per [the visual theme system](visual-theme-system.md#customizing-text-content). |
| 29 | +- `public/` - OPTIONAL - A folder containing any files to expose into public web-space as per [the visual theme system](visual-theme-system.md#publicly-accessible-files). |
| 30 | +- `views/` - OPTIONAL - A folder containing any view additions or overrides as per [the visual theme system](visual-theme-system.md#customizing-view-files). |
| 31 | + |
| 32 | +You can create additional directories/files for your own needs within the module, but ideally name them something unique to prevent conflicts with the above structure. |
| 33 | + |
| 34 | +### Module JSON Metadata |
| 35 | + |
| 36 | +Modules are required to have a `bookstack-module.json` file in the top level directory of the module. |
| 37 | +This must be a JSON file with the following properties: |
| 38 | + |
| 39 | +- `name` - string - An (ideally unique) name for the module. |
| 40 | +- `description` - string - A short description of the module. |
| 41 | +- `version` - string - A string version number generally following [semantic versioning](https://semver.org/). |
| 42 | + - Examples: `v0.4.0`, `4.3.12`, `v0.1.0-beta4`. |
| 43 | + |
| 44 | +### Customization Order/Precedence |
| 45 | + |
| 46 | +It's possible that multiple modules may override/customize the same content. |
| 47 | +Right now, there's no assurance in regard to the order in which modules may be loaded. |
| 48 | +Generally they will be used/searched in order of their module folder name, but this is not assured and should not be relied upon. |
| 49 | + |
| 50 | +It's also possible that modules customize the same content as the configured theme. |
| 51 | +In this scenario, the theme takes precedence. Modules are designed to be more portable and instance abstract, whereas the theme folder would typically be specific to the instance. |
| 52 | +This allows the theme to be used to customize or override module content for the BookStack instance, without altering the module code itself. |
| 53 | + |
| 54 | +### Module Best Practices |
| 55 | + |
| 56 | +Here are some general best practices when it comes to creating modules: |
| 57 | + |
| 58 | +- Use a unique name and clear description so the user can understand the purpose of the module. |
| 59 | +- Increment the metadata version on change, keeping to [semver](https://semver.org/) to indicate compatibility of new versions. |
| 60 | +- Where possible, prefer to [insert views before/after](logical-theme-system.md#custom-view-registration-example) instead of overriding existing views, to reduce likelihood of conflicts or update troubles. |
0 commit comments