Skip to content

Commit

Permalink
Added bodyclass for controller posibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mareksriska committed Mar 16, 2018
1 parent 910f6d8 commit 00df204
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Handlers/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,28 @@ public function setRoute(RouteInterface $route) {
}

public function handle() {

$this->setBodyClass();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$this->post();
} else {
$this->get();
}

}

/*
* Adds templates name with -data to body class, only needed if using soberwp/controller
*/
public function setBodyClass() {
add_filter('body_class', function ($classes) {

$found = [];
preg_match('/\/(\w+)(?:\.blade)?\.php$/', $this->templates[0], $found);

return array_merge($classes, [$found[1] . '-data']);
});
}

public function get() {
Expand Down

0 comments on commit 00df204

Please sign in to comment.