Last active
October 12, 2016 16:05
-
-
Save chrisdempsey/e6f4bba1583c22ed55f4d164fceb7fc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* activateAssets | |
* | |
* DESCRIPTION | |
* | |
* Activates assets registered in placeholder. | |
* | |
* PROPERTIES: | |
* | |
* None, works from placeholder created by registerAssets | |
* | |
* USAGE: | |
* | |
* [[-activateAssets]] | |
* | |
*/ | |
if (!isset($modx)) return; | |
// head.js handles css and js at the same time | |
$files = $modx->getPlaceholder('placeholderAssets'); | |
if (!empty($files)) { | |
// write filenames to log for debugging | |
// $modx->log(modX::LOG_LEVEL_ERROR, '[placeholderAssets] activated files: ' . $files); | |
// remove trailing pipes from $files string | |
$files = rtrim($files,'||'); | |
// strip white spae from $files | |
$files = preg_replace('/\s+/', '', $files); | |
// create array of files by splitting file_list on pipes | |
$arr_files = explode("||", $files); | |
// loop through array and register file by type | |
foreach ($arr_files as $file) { | |
$output .= "head.load( '$file' );\n"; | |
} | |
} | |
// if output has been generated register ClientHTMLBlock and inject before the closing BODY tag | |
if (!empty($output)) $modx->regClientHTMLBlock("<script type='text/javascript'>\n$output\n</script>"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment