Skip to content

Commit 0ad09ef

Browse files
Make regClientScript and regClientHTMLBlock work in the manager (#16700)
### What does it do? Adds scripts registered with `regClientScript()` or `regClientHTMLBlock()` to the output in the manager. ### Why is it needed? There is some inconsistency: The _modX_ class has the 4 functions `regClientScript()`, `regClientHTMLBlock()`, `regClientStartupScript()` and `regClientStartupHTMLBlock()`. On the _frontend_ (outputting a resource) all 4 functions work. In the _manager_, the functions `regClientStartupScript()` and `regClientStartupHTMLBlock()` work, but scripts registered with `regClientScript()` and `regClientHTMLBlock()` are ignored. --- If there is a reason why these functions shouldn't work in the manager, then at least the MODX documentation (and the source code) should be updated to clearly state that this is the case. ### How to test * Create a plugin that uses the functions `$modx->regClientScript()` and `$modx->regClientHTMLBlock()` on a manager event (like e.g. `OnManagerPageBeforeRender`). * Make sure the scripts get added to the HTML output. ### Related issue(s)/PR(s) Related discussion in the MODX forum: https://community.modx.com/t/13-years-and-6-months-regclientscript-still-not-working/8282
1 parent 8179e04 commit 0ad09ef

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

core/src/Revolution/modManagerController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ public function registerCssJs()
787787
$cssjs[] = $scr;
788788
}
789789

790-
791790
$lastjs = [];
792791
foreach ($this->head['lastjs'] as $js) {
793792
$lastjs[] = $js;
@@ -798,8 +797,14 @@ public function registerCssJs()
798797
}
799798
}
800799

801-
802800
$this->modx->smarty->assign('cssjs', $cssjs);
801+
802+
$jsbody = [];
803+
foreach ($this->modx->jscripts as $scr) {
804+
$scr = $this->_postfixVersionToScript($scr, $versionPostFix);
805+
$jsbody[] = $scr;
806+
}
807+
$this->modx->smarty->assign('jsbody', $jsbody);
803808
}
804809

805810
/**

manager/templates/default/footer.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
</div>
55
<!-- #modx-container -->
66

7+
{foreach from=$jsbody item=scr}
8+
{$scr}
9+
{/foreach}
10+
711
</body>
812
</html>

0 commit comments

Comments
 (0)