Render "after_javascript" block after other scripts

[MAILPOET-5118]
This commit is contained in:
Jan Jakes
2023-09-28 15:13:50 +02:00
committed by Aschepikov
parent 3106b19684
commit 2a676353aa
3 changed files with 44 additions and 6 deletions

View File

@@ -100,7 +100,18 @@ class Renderer {
public function render($template, $context = []) {
try {
return $this->renderer->render($template, $context);
$loaded = $this->renderer->load($template);
// schedule "after_javascript" block to be printed only after other scripts
if ($loaded->hasBlock('after_javascript')) {
$afterJs = $loaded->renderBlock('after_javascript', $context);
WPFunctions::get()->addAction('admin_print_footer_scripts', function () use ($afterJs): void {
// This is content is generated by Twig.
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPressDotOrg.sniffs.OutputEscaping.UnescapedOutputParameter
echo $afterJs;
});
}
return $loaded->render($context);
} catch (\RuntimeException $e) {
throw new \Exception(sprintf(
// translators: %1$s is the name of the render, %2$s the folder path, %3$s the error message.