diff --git a/app/rendering.php b/app/rendering.php index 1ee87e1..7ed8670 100644 --- a/app/rendering.php +++ b/app/rendering.php @@ -20,7 +20,7 @@ function renderContentFile(string $filePath, ?Context $ctx = null): string { if (!class_exists('ParsedownExtra')) { require_once __DIR__ . '/vendor/ParsedownExtra.php'; } - $html = '
' . (new ParsedownExtra())->text(file_get_contents($filePath)) . '
'; + $html = (new ParsedownExtra())->text(file_get_contents($filePath)); if ($langPrefix) { $html = preg_replace( @@ -73,13 +73,14 @@ function renderFile(Context $ctx, string $filePath): void { $ext = pathinfo($realPath, PATHINFO_EXTENSION); if (in_array($ext, CONTENT_EXTENSIONS)) { - $content = renderContentFile($realPath, $ctx); - + // Load metadata and page plugins BEFORE rendering content + // so that plugin-provided template variables are available to PHP content files $pageDir = dirname($realPath); $pageMetadata = loadMetadata($pageDir); - getPluginManager()->loadPagePlugins($pageMetadata); + $content = renderContentFile($realPath, $ctx); + $navigation = $ctx->navigation; $homeLabel = $ctx->homeLabel; $pageTitle = $pageMetadata['title'] ?? null; @@ -122,15 +123,16 @@ function renderFile(Context $ctx, string $filePath): void { } function renderMultipleFiles(Context $ctx, array $files, string $pageDir): void { + // Load metadata and page plugins BEFORE rendering content files + // so that plugin-provided template variables are available to PHP content files + $pageMetadata = loadMetadata($pageDir); + getPluginManager()->loadPagePlugins($pageMetadata); + $content = ''; foreach ($files as $file) { $content .= renderContentFile($file, $ctx); } - $pageMetadata = loadMetadata($pageDir); - - getPluginManager()->loadPagePlugins($pageMetadata); - $navigation = $ctx->navigation; $homeLabel = $ctx->homeLabel; $pageTitle = $pageMetadata['title'] ?? null;