Files
hocusfokus-web/kirby/src/Toolkit/Tpl.php
Bastian Allgeier 6e5c9d1f48 Upgrade to 3.9.0
2023-01-17 14:50:16 +01:00

49 lines
798 B
PHP

<?php
namespace Kirby\Toolkit;
use Kirby\Filesystem\F;
use Throwable;
/**
* Simple PHP template engine
*
* @package Kirby Toolkit
* @author Bastian Allgeier <bastian@getkirby.com>
* @link https://getkirby.com
* @copyright Bastian Allgeier
* @license https://opensource.org/licenses/MIT
*/
class Tpl
{
/**
* Renders the template
*
* @throws Throwable
*/
public static function load(string|null $file = null, array $data = []): string
{
if ($file === null || is_file($file) === false) {
return '';
}
ob_start();
$exception = null;
try {
F::load($file, null, $data);
} catch (Throwable $e) {
$exception = $e;
}
$content = ob_get_contents();
ob_end_clean();
if ($exception === null) {
return $content;
}
throw $exception;
}
}