diff --git a/public/index.php b/public/index.php index a851cb5..f54c7fe 100644 --- a/public/index.php +++ b/public/index.php @@ -43,21 +43,32 @@ if ($uriPath === '' || $uriPath === 'index' || $uriPath === 'index.php') { // Layout-Regel // ------------------------------------ $skipLayout = false; +$targetReal = realpath($target); // Beispiel: alles unter /page/raw/* ohne Layout -if (str_starts_with(realpath($target), realpath(__DIR__ . '/page/retool'))) { +if ($targetReal && str_starts_with($targetReal, realpath(__DIR__ . '/page/retool'))) { $skipLayout = true; } // ------------------------------------ // Ausgabe // ------------------------------------ +// Erst Inhalt laden (ohne Ausgabe), damit Header/Redirects vor HTML funktionieren +ob_start(); +require $target; +$content = ob_get_clean(); + +// Wenn bereits Header gesendet wurden (z. B. eigener Redirect/Content-Type), Layout überspringen +if (headers_sent()) { + $skipLayout = true; +} + if (!$skipLayout) { tpl('layout_start', 'structure'); } -require $target; +echo $content; if (!$skipLayout) { tpl('layout_end', 'structure'); -} \ No newline at end of file +}