Twig: Extract renderInline(content, context) as method to $twig

This commit is contained in:
slawkens
2026-01-28 21:59:31 +01:00
parent 8dcbb66753
commit 5e4806f891
2 changed files with 19 additions and 12 deletions

View File

@@ -3,6 +3,7 @@
namespace MyAAC\Twig;
use Twig\Environment;
use Twig\Loader\ArrayLoader as Twig_ArrayLoader;
class EnvironmentBridge extends Environment
{
@@ -25,4 +26,21 @@ class EnvironmentBridge extends Environment
return parent::render($name, $context);
}
public function renderInline($content, array $context = []): string
{
$oldLoader = $this->getLoader();
$twig_loader_array = new Twig_ArrayLoader(array(
'content.html' => $content
));
$this->setLoader($twig_loader_array);
$ret = $this->render('content.html', $context);
$this->setLoader($oldLoader);
return $ret;
}
}