Welcome to 3DMICK
+91 (971) 119-1127

ZEND HeadScript Helper

ZEND HeadScript Helper

In  HTML  <script> element tag  is used to provide client-side scripting e.g  javascript or it points the external script file through src attribute.
The HeadScript helper supports the following methods for setting and adding scripts:

To put the script in a specific order we use append,prepend,offsetSet directives.

1. appendFile($src, $type = ‘text/javascript’, $attrs = array())
$src=we will provide the source file which we want to append.
$attrs = array();
e.g ->appendFile( $this->baseUrl('js/lib/jquery/jquery-1.4.2.min.js') )

2.  offsetSetFile($index, $src, $type = ‘text/javascript’, $attrs = array())
e.g $this->headScript()->offsetSetFile(999, '/js/abcd.js');

3.  prependFile($src, $type = ‘text/javascript’, $attrs = array())
If you want to load your script first the we will use the prependFile() method.To put        scripts in a particular order we use these methods.


4. setFile($src, $type = ‘text/javascript’, $attrs = array())

5.appendScript($script, $type = ‘text/javascript’, $attrs = array())

6. offsetSetScript($index, $script, $type = ‘text/javascript’, $attrs = array())

7. prependScript($script, $type = ‘text/javascript’, $attrs = array())

8. setScript($script, $type = ‘text/javascript’, $attrs = array())

In the above  methods  for *File()  methods  if we want to load the script from remote location we will mention it in $src parameter  where we will give in the form of url or path. For  *Script() methods  $script is the client-side scripting directives you wish to use in the element.

Setting  Conditional Comments:

To add the specific browser condition HeadScript allow you to wrap the script in conditional comments.To add the conditional tags we will pass the conditional value in the $attrs parameter in the method calls.

For Example:
HeadScript with Conditional Comments

appendScript($script, $type = 'text/javascript', $attrs = array())
// adding scripts
array('conditional' => 'lt IE 7')