$modx->regClientStartupScript(’/assets/js/jquery.js’);
<?php
global $modx;
$output= $modx->documentOutput;
$site_url = MODX_BASE_URL;
ob_start();
// Define the CSS and Javascript that we will add to the header of the page
$head =<<<EOD
<!-- Start Xedit headers -->
<script src="{$site_url}assets/plugins/multi_chunk_Tvs/js/mootools-1.2.1.js" type="text/javascript"></script>
<script src="{$site_url}assets/plugins/multi_chunk_Tvs/js/mootools-1.2-more.js" type="text/javascript"></script>
<script src="{$site_url}assets/plugins/multi_chunk_Tvs/js/blox_sortables.js" type="text/javascript"></script>
<script type="text/javascript">
window.addEvent('domready', function(){
//your startup scripts
});
</script>
<!-- End Xedit headers -->
EOD;
// If the javascript hasn't already been added to the page, do it now
if (strpos($output, $head) === false)
{
//$output = str_replace('</head>', $head, $output);
$output = preg_replace('~(</head>)~i', $head.'\1', $output);
}
ob_flush();
$modx->documentOutput = $output;
?>
You can try something like that in onWebPagePrerender (mootools example):
<?php global $modx; $output= $modx->documentOutput; $site_url = MODX_BASE_URL; ob_start(); // Define the CSS and Javascript that we will add to the header of the page $head =<<<EOD <!-- Start Xedit headers --> <script src="{$site_url}assets/plugins/multi_chunk_Tvs/js/mootools-1.2.1.js" type="text/javascript"></script> <script src="{$site_url}assets/plugins/multi_chunk_Tvs/js/mootools-1.2-more.js" type="text/javascript"></script> <script src="{$site_url}assets/plugins/multi_chunk_Tvs/js/blox_sortables.js" type="text/javascript"></script> <script type="text/javascript"> window.addEvent('domready', function(){ //your startup scripts }); </script> <!-- End Xedit headers --> EOD; // If the javascript hasn't already been added to the page, do it now if (strpos($output, $head) === false) { //$output = str_replace('</head>', $head, $output); $output = preg_replace('~(</head>)~i', $head.'\1', $output); } ob_flush(); $modx->documentOutput = $output; ?>
if( $TVarray = $modx->getTemplateVarOutput(array(ceebox-flag)) ){ $tvOutput = $TVarray[ceebox-flag];
if( $tvOutput == "Yes" || $tvOutput == "yes" ) {
$tvOutput = "<script type='text/javascript' src='/assets/js/ceebox/ceebox.js'></script>";
$tvOutput .= "<link type='text/css' src='assets/js/ceebox/ceebox.css' media='screen' />";
echo $tvOutput;
}
}
if( $TVarray = $modx->getTemplateVarOutput(array(ceebox-flag)) ){ $tvOutput = $TVarray[ceebox-flag]; if( $tvOutput == "Yes" || $tvOutput == "yes" ) { $tvOutput = "<script type='text/javascript' src='/assets/js/ceebox/ceebox.js'></script>"; $tvOutput .= "<link type='text/css' src='assets/js/ceebox/ceebox.css' media='screen' />"; echo $tvOutput; } }
$tvOutput is always empty when I check for the "Yes" value even if the box is checked in the TV for the page in the MODx manager. I’m brand new to MODx CMS (and have done some forum and documentation searching) and I suspect I’m missing something fairly simple.
Are you able to see what I’m doing wrong? Or is there a simpler way to use your code for what I’m trying to do?
Thanks for your help.
if( $TVarray = $modx->getTemplateVarOutput(array('ceebox-flag')) ){ $tvOutput = $TVarray['ceebox-flag'];
if( $tvOutput == "Yes" || $tvOutput == "yes" ) {
//load the jQuery library
$src = "/assets/js/ceebox/jquery.js";
$modx->regClientStartupScript($src);
//load the Ceebox script
$src = "/assets/js/ceebox/ceebox.js";
$modx->regClientStartupScript($src);
//load the Ceebox CSS
$src = '<link rel="stylesheet" type="text/css" href="/assets/js/ceebox/ceebox.css" media="screen" />';
$modx->regClientStartupHTMLBlock($src);
}
}