Skip to content

Commit 4d4da34

Browse files
authored
Adding render after hook (#16)
1 parent 1685fd8 commit 4d4da34

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,29 @@ After declaration you can use it like:
144144
@endlogged
145145
```
146146

147+
### Hook
148+
149+
For use cases such as HTML minification, there's a custom hook for manipulating rendered HTML output:
150+
151+
```php
152+
# site/config/config.php
153+
154+
# For this example, we are using 'voku/html-min'
155+
use voku\helper\HtmlMin;
156+
157+
return [
158+
# ...
159+
160+
'hooks' => [
161+
'blade.render:after' => function (string $html): string {
162+
return (new HtmlMin())->minify($html);
163+
},
164+
],
165+
166+
# ...
167+
];
168+
```
169+
147170
## Credits
148171
- [Kirby Blade](https://github.com/afbora/kirby-blade) by [@afbora](https://github.com/afbora)
149172
- [Torch](https://github.com/mattstauffer/Torch) by [@mattstauffer](https://github.com/mattstauffer)

src/Template.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ public function render(array $data = []): string
3434
View::share('pages', $data['pages']);
3535
View::share('page', $data['page']);
3636

37-
return View::file($this->file(), $data)->render();
37+
$html = View::file($this->file(), $data)->render();
38+
} else {
39+
$html = Tpl::load($this->file(), $data);
3840
}
3941

40-
return Tpl::load($this->file(), $data);
42+
return App::instance()->apply('blade.render:after', compact('html'), 'html');
4143
}
4244

4345
public function isBlade(): bool

0 commit comments

Comments
 (0)