hanyuu/src/Templating/TemplateBlock.php

23 lines
457 B
PHP

<?php
namespace Hanyuu\Templating;
use Closure;
class TemplateBlock {
public function __construct(
private object $self,
private mixed $body
) {}
public function render(): string {
if(is_callable($this->body)) {
ob_start();
($this->body)($this->self);
$body = ob_get_contents();
ob_end_clean();
} else $body = strval($this->body);
return $body;
}
}