otWebsiteRepository->getCurrentWebsiteFromFEGlobals(); $matomoSiteId = $website['matomo_site_id']; if (!$matomoSiteId > 0) { // stats are not enabled, continue return $handler->handle($request); } // render view $view = GeneralUtility::makeInstance(StandaloneView::class); $view->setTemplateRootPaths([self::TEMPLATES_ROOT_PATHS]); $view->setPartialRootPaths([self::PARTIALS_ROOT_PATHS]); $view->setLayoutRootPaths([self::LAYOUTS_ROOT_PATHS]); $view->setTemplatePathAndFilename( GeneralUtility::getFileAbsFileName(self::TEMPLATE_FILE) ); // Build the response $response = $handler->handle($request); // insert the rendered view in the body, just before the closing tag $newSection = $view->render(); $bodyContent = (string)$response->getBody(); $bodyContent = str_replace('', $newSection . '', $bodyContent); $newBody = new Stream('php://temp', 'wb+'); $newBody->write($bodyContent); $newBody->rewind(); $response = $response->withBody($newBody); return $response; } }