php - Placement of conditional script in head section of a layout -


In my layout I am using a bunch of JavaScript scripts. Two of these scripts are conditional and they should be loaded for IE9 only. And everyone else should be loaded for all browsers.

To achieve this, I have done the following in my bootstrap class.

  $ this-> Headset () - & gt; Append file ('//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js', 'text / javascript', array ('conditional' => 'LT IE9')); $ This- & gt; _view-> Headset () - & gt; Append file ('//oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js', 'text / javascript', array ('conditional' => 'LT IE9')) ; $ This- & gt; _view-> Headset () - & gt; Attachment file ($ this-> _view- & gt; Baseput ('/assets/js/scripts.min.js?ver=1.0.0'));   

This works and I get the output in my layout.

  & lt ;! - [If Lieutenant IE 9] & gt; & Lt; Script type = "text / javascript" src = "// oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script><![endif]--> & Lt ;! - [If LT IE 9] & gt; & Lt; Script type = "text / javascript" src = "// oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script><![section] - & Gt; & Lt; Script type = "text / javascript" src = "http://om.localhost.com/assets/js/scripts.min.js?ver=1.0.0" & gt; & Lt; / Script & gt;   

The above output is OK. But it has been recommended that I put the conditional script in the main part of the layout and put the remaining scripts at the end of the body.

Is there a way to get it into ZF1?

PS I have tried to use placeholders but it has not worked and I do not want to do this script hard code in the layout.

Thank you for your help.

In the head section, you can type the code like headset () .
At the end of the body, you can use the InlineScript () method like this:

  $ this-> View- & gt; Inline script () - & gt; Append file ($ this-> view- & gt; base URL) '/ Js / myfile.js');   

and add to the end of your layout:

  & lt; php echo $ this- & gt; Inline script (); ? & Gt;   

To add scripts to the bootstrap, you can do something like this:

  Secure function_initView () {$ options = $ this- & gt; GetOptions (); If (isset ($ option ['resource'] ['view'])) {$ view = new Zend_View ($ option ['resource'] ['view']); } And {$ view = new Zend_View; } $ View-> Inline script () - & gt; Append file (...); }    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -