initial COmmit: Add KB Antora Importer plugin files
This commit is contained in:
28
kb-antora-importer/includes/Frontend/TemplateLoader.php
Normal file
28
kb-antora-importer/includes/Frontend/TemplateLoader.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KbAntoraImporter\Frontend;
|
||||
|
||||
final class TemplateLoader
|
||||
{
|
||||
public function render(string $template, array $vars = []): void
|
||||
{
|
||||
$path = KB_ANTORA_IMPORTER_DIR . 'templates/' . $template . '.php';
|
||||
|
||||
if (! is_readable($path)) {
|
||||
status_header(500);
|
||||
echo esc_html__('Knowledgebase template missing.', 'kb-antora-importer');
|
||||
return;
|
||||
}
|
||||
|
||||
extract($vars, EXTR_SKIP);
|
||||
include $path;
|
||||
}
|
||||
|
||||
public function capture(string $template, array $vars = []): string
|
||||
{
|
||||
ob_start();
|
||||
$this->render($template, $vars);
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user