Friday, 7 November 2014

View Helper - InlineScript : Use InlineScript for HTML Body Scripts



How To Use InlineScript for HTML Body Scripts

he HTML <script> element is used to either provide inline client-side scripting elements or link to a remote resource containing client-side scripting code.
The InlineScript helper allows you to manage both. It is derived from HeadScript, and any method of that helper is available;
however, use the inlineScript() method in place of headScript();
 

===============================================
Note::Use InlineScript for HTML Body Scripts
InlineScript, should be used when you wish to include scripts inline in the HTML body.
Placing scripts at the end of your document is a good practice for speeding up delivery of your page,
particularly when using 3rd party analytics scripts.
Some JS libraries need to be included in the HTML head; use HeadScript for those scripts.

===============================================
 



-:: Basic Usage ::-
Add to the layout script:

 ===============================================<body>
    <!-- Content -->


    <?php
    echo $this->inlineScript()->prependFile($this->basePath('js/vendor/foundation.min.js'))
                              ->prependFile($this->basePath('js/vendor/jquery.js'));
    ?>
</body>

===============================================
-:: Output ::-

===============================================
<body>
    <!-- Content -->

    <script type="text/javascript" src="/js/vendor/jquery.js"></script>
    <script type="text/javascript" src="/js/vendor/foundation.min.js"></script>
</body>

===============================================
-:: Capturing Scripts ::-
Add in your view scripts:

===============================================
 $this->inlineScript()->captureStart();
echo <<<JS
    $('select').change(function(){
        location.href = $(this).val();
    });
JS;
$this->inlineScript()->captureEnd();


===============================================
 -:: Output ::-
===============================================<body>


    <!-- Content -->

    <script type="text/javascript" src="/js/vendor/jquery.js"></script>
    <script type="text/javascript" src="/js/vendor/foundation.min.js"></script>
    <script type="text/javascript">
        //<!--
        $('select').change(function(){
            location.href = $(this).val();
        });
        //-->
    </script>
</body>



-:: More Details On ::-
===============================================| Source:: http://framework.zend.com/manual/2.2/en/modules/zend.view.helpers.inline-script.html  |===============================================

No comments:

Post a Comment