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

@@ -21,7 +21,6 @@ use MyAAC\News;
use MyAAC\Plugins;
use MyAAC\Settings;
use PHPMailer\PHPMailer\PHPMailer;
use Twig\Loader\ArrayLoader as Twig_ArrayLoader;
function message($message, $type, $return)
{
@@ -1379,17 +1378,7 @@ function getCustomPage($name, &$success): string
ob_end_clean();
}
else {
$oldLoader = $twig->getLoader();
$twig_loader_array = new Twig_ArrayLoader(array(
'content.html' => $page['body']
));
$twig->setLoader($twig_loader_array);
$content .= $twig->render('content.html');
$twig->setLoader($oldLoader);
$content .= $twig->renderInline($page['body']);
}
}

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;
}
}