Skip to content

Commit

Permalink
Adding render after hook (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
S1SYPHOS authored Jul 6, 2022
1 parent 1685fd8 commit 4d4da34
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,29 @@ After declaration you can use it like:
@endlogged
```

### Hook

For use cases such as HTML minification, there's a custom hook for manipulating rendered HTML output:

```php
# site/config/config.php

# For this example, we are using 'voku/html-min'
use voku\helper\HtmlMin;

return [
# ...

'hooks' => [
'blade.render:after' => function (string $html): string {
return (new HtmlMin())->minify($html);
},
],

# ...
];
```

## Credits
- [Kirby Blade](https://github.com/afbora/kirby-blade) by [@afbora](https://github.com/afbora)
- [Torch](https://github.com/mattstauffer/Torch) by [@mattstauffer](https://github.com/mattstauffer)
Expand Down
6 changes: 4 additions & 2 deletions src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ public function render(array $data = []): string
View::share('pages', $data['pages']);
View::share('page', $data['page']);

return View::file($this->file(), $data)->render();
$html = View::file($this->file(), $data)->render();
} else {
$html = Tpl::load($this->file(), $data);
}

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

public function isBlade(): bool
Expand Down

0 comments on commit 4d4da34

Please sign in to comment.