Render "after_javascript" block after other scripts
[MAILPOET-5118]
This commit is contained in:
@@ -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.
|
||||
|
Reference in New Issue
Block a user