Skip to content

Commit 57bcda1

Browse files
Update README.md
1 parent 9fa083c commit 57bcda1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,32 @@ return function (string $title = 'Default Title', ...$args) {
7171
};
7272
```
7373

74+
> **Note**
75+
> Since version [`2.1.0`](https://github.com/lukaskleinschmidt/kirby-snippet-controller/releases/tag/2.1.0) you can override variables when using a controller callback.
76+
77+
```php
78+
snippet('header', data: ['size' => $page->size()])
79+
80+
// header.controller.php
81+
82+
return function (Field|string $size = null) {
83+
84+
if ($size instanceof Field) {
85+
$size = $size->value();
86+
}
87+
88+
$size = match ($size) {
89+
'small' => 'height: 50vh',
90+
'medium' => 'height: 80vh',
91+
default => 'height: 100vh',
92+
};
93+
94+
return [
95+
'size' => $size,
96+
];
97+
};
98+
```
99+
74100
### Naming convention
75101
By default, the plugin searches for controllers by appending `.controller` to the snippet name.
76102
You can change the name resolver in the options. Changing the name also affects plugin-defined controllers.

0 commit comments

Comments
 (0)