What can be extended
On this page
Extension points
An extension point is a place in the application lifecycle where you can add your own code. Herbie provides these extension points:
| Extension point | Typical use | Difficulty | Frequency |
|---|---|---|---|
| Console command | Provide functionality in the CLI | Medium | Rare |
| Event listener | React to system events | Medium | Rare |
| Application middleware | Modify HTTP requests and responses | Medium | Rare |
| Route middleware | Modify HTTP requests and responses for matching routes | Medium | Rare |
| Twig filter | Transform values in templates | Very easy | Frequent |
| Twig global | Provide a global value or helper object | Very easy | Frequent |
| Twig function | Generate content in templates | Very easy | Frequent |
| Twig test | Evaluate boolean conditions in templates | Very easy | Frequent |
For details on specific extension points, see Commands, Event Listeners, Middlewares, Twig Filters, Twig Functions, Twig Globals, and Twig Tests.
Choosing a method
There are four ways to add extensions, with increasing flexibility and complexity.
- Files in site/extend: Best for small, project-specific extensions that should be quick to add.
- Register in index.php: Useful when extensions should be registered explicitly in
index.php, for example alongside other startup code. - Plugin class: Suitable for grouping related extensions in one class, with optional configuration and dependency checks.
- Composer package: Use this when an extension should be versioned, shared, and installed via Composer.