mirror of
https://github.com/slawkens/myaac.git
synced 2026-02-03 03:46:22 +01:00
Twig: Extract renderInline(content, context) as method to $twig
This commit is contained in:
@@ -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']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user