Skip to content

Instantly share code, notes, and snippets.

@silentworks
Created March 20, 2013 12:13
Show Gist options
  • Save silentworks/5204211 to your computer and use it in GitHub Desktop.
Save silentworks/5204211 to your computer and use it in GitHub Desktop.
Including CSS and JS in any page to head and before body tag
<?php
/*
* Register CSS and JS to load in head of website
*/
$link = $modx->getOption('link', $scriptProperties, '');
if (empty($link)) {
return false;
}
$links = explode(',', preg_replace('/\s+/', '', $link));
foreach ($links as $lnk) {
list($type, $lnk) = explode('||', $lnk);
if ($type === 'css') {
$modx->regClientCSS($lnk);
}
if ($type === 'js') {
$modx->regClientScript($lnk);
}
}
How to use
[[!cssJSRegister?link=`
css||/assets/css/flexslider.css,
js||/assets/js/jquery.flexslider-min.js,
js||/assets/js/global.js
`]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment