Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
regClient: Move stuff around inside your modx template
<?php
/*
Reposition Blocks of Code:
--------------------------
[[!regClient?
&value=`code block or file url`
&option=`regClientCSS`
]]
&option - Pick one of the regClient functions
&value - Whatever you want to put inside
*/
/*
==Default (Code stays here!)
regClientStartupHTMLBlock==HTML - Move to HEAD (regClientStartupHTMLBlock)
regClientHTMLBlock==HTML - Move to BOTTOM (regClientHTMLBlock)
regClientCSS==CSS - Move to HEAD (regClientCSS)
regClientStartupScript==JS - Move to HEAD (regClientStartupScript)
regClientScript==JS - Move to BOTTOM (regClientScript)
*/
/*
regClientCSS (send css file OR code to head)
--------------------------------------------
Register CSS to be injected inside the HEAD tag of a resource.
https://docs.modx.com/current/en/extending-modx/modx-class/reference/modx.regclientcss
Example: Register a CSS file to the HEAD tag for all 'media'
--------
* $modx->regClientCSS('assets/css/style.css' , 'all');
* $modx->regClientCSS('<style>body {}</style>');
JS
regClientStartupScript (send js file OR script tag to head)
-----------------------------------------------------------
Register JavaScript to be injected inside the HEAD tag of a resource.
https://docs.modx.com/current/en/extending-modx/modx-class/reference/modx.regclientstartupscript
Example: Register some JS to the start of the page:
--------
* $modx->regClientStartupScript('assets/js/onload.js');
* $modx->regClientStartupScript('//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"');
* $modx->regClientStartupScript('http://code.jquery.com/jquery-latest.min.js');
* $modx->regClientStartupScript('<script>console.log('Hi')</script>');
regClientScript (send file OR script tag to bottom)
---------------------------------------------------
Register JavaScript to be injected BEFORE the closing BODY tag.
https://docs.modx.com/current/en/extending-modx/modx-class/reference/modx.regclientscript
Example: Add some JS to the end of the page.
--------
* $modx->regClientScript('assets/js/footer.js');
* $modx->regClientScript('script>console.log('hello world!')</script>');
HTML
regClientStartupHTMLBlock (send html tag to head)
-------------------------------------------------
Register HTML to be injected BEFORE the closing HEAD tag.
https://docs.modx.com/current/en/extending-modx/modx-class/reference/modx.regclientstartuphtmlblock
Example: Render a faux tag element before the end of the HEAD
--------
* $modx->regClientStartupHTMLBlock('<meta name="" content="">');
regClientHTMLBlock (send html tag to bottom)
--------------------------------------------
Register HTML to be injected BEFORE the closing BODY tag.
https://docs.modx.com/current/en/extending-modx/modx-class/reference/modx.regclienthtmlblock
Example: Inject a footer into the page.
--------
* $modx->regClientHTMLBlock('<div id="footer">(c) 2009 MODX</div>');
*/
switch($option){
case 'regClientCSS':
$modx->regClientCSS($value);
break;
case 'regClientHTMLBlock':
$modx->regClientHTMLBlock($value);
break;
case 'regClientScript':
$modx->regClientScript($value);
break;
case 'regClientStartupHTMLBlock':
$modx->regClientStartupHTMLBlock($value);
break;
case 'regClientStartupScript':
$modx->regClientStartupScript($value);
break;
default:
return $value;
}
return '';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment