diff --git a/Handlers/RequestHandler.php b/Handlers/RequestHandler.php index 34ebdc7..7ec0c15 100644 --- a/Handlers/RequestHandler.php +++ b/Handlers/RequestHandler.php @@ -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() {