4

I have a partial which loads all common links and styles in head and I use setScript in other pages for local scripts. I want to add the following script which is located in my view/scripts after other scripts but zf appends it at first:

<? $this->headScript()->setScript('$(document).ready(function() {
        $("#birthdate").datepicker();
        });', 
    $type = 'text/javascript') ?>

which leads to following code:

<script type="text/javascript">
    $(document).ready(function() {
        $("#birthdate").datepicker();
        });
</script>
<script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/js/jquery.dcmegamenu.1.3.3.min.js"></script>
<script type="text/javascript" src="/js/jquery.hoverIntent.minified.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.16.custom.min.js"></script>

but I want:

<script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/js/jquery.dcmegamenu.1.3.3.min.js"></script>
<script type="text/javascript" src="/js/jquery.hoverIntent.minified.js"></script>
<script type="text/javascript" src="/js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#birthdate").datepicker();
        });
</script>

1 Answer 1

6

Try calling:

<? $this->headScript()->appendScript('$(document).ready(function() {
        $("#birthdate").datepicker();
        });', 
    $type = 'text/javascript') ?>

Try adding your other files using:

<? $this->setScript()
->prependFile('/js/jquery-ui-1.8.16.custom.min.js')
->prependFile('/js/jquery.hoverIntent.minified.js') 
->prependFile('/js/jquery.dcmegamenu.1.3.3.min.js') 
->prependFile('/js/jquery-1.7.1.min.js') ;
?>
Sign up to request clarification or add additional context in comments.

3 Comments

How are you adding the other scripts to the header?
Here is the code: <?= $this->setScript()->setFile('/js/jquery-1.7.1.min.js') ->setFile('/js/jquery.dcmegamenu.1.3.3.min.js') ->setFile('/js/jquery.hoverIntent.minified.js') ->setFile('/js/jquery-ui-1.8.16.custom.min.js'); ?>
@Brian Fisher do you know maybe how to do this in codeigniter? Or can you explain me how setScript()->setFile() is working?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.