Код: Выделить всё
public function renderComponent(string $templatePath, ViewComponentEntityInterface $component): string
{
if (! file_exists($templatePath)) {
throw new RuntimeException('Incorrect component template path: ' . $templatePath);
}
$viewHelper = $this->viewHelperFactory->create();
ob_start();
try {
(static function (ViewComponentEntityInterface $template,ViewHelper $viewHelper) use ($templatePath) {
include $templatePath;
})($component, $viewHelper);
return ob_get_clean();
} catch (Throwable $e) {
ob_end_clean();
throw $e;
}
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... put-buffer
Мобильная версия