add_js()

From SkyPHP

Jump to: navigation, search

If you need to link js or css files within the <body> tag, use the following functions to maintain web standards compliance. Sometimes this function is necessary, but should be avoided when possible.

<script type="text/javascript"> 
	add_css("/pages/login/login.css");
	add_js('/pages/login/login.js');
</script> 

The better option is to add your link/script tags to the $head_arr variable before including the global template.

<?
    $head_arr[] = '<script src="/lib/js/cufon-yui.js" type="text/javascript"></script>',
    $head_arr[] = '<script src="/lib/js/Univers_LT_Std_400.font.js" type="text/javascript"></script>
                   <script type="text/javascript">
                       Cufon.replace(".univ");
                   </script>';
?>

NOTE: If you are adding to $head_arr WITHIN A TEMPLATE, you will need to use the $GLOBALS array to set the variable due to the scope issues:

<?
if ( $template_area == 'top' ) {
	
    $GLOBALS['head_arr']=array('
        <script src="/lib/js/cufon-yui.js" type="text/javascript"></script>
        <script src="/lib/fonts/altgoth_400.font.js" type="text/javascript"></script>
        <script type="text/javascript">
            Cufon.replace(".altgoth");
        </script>');

	
	template::inc('global','top');
?>
. . .
Personal tools