Including jQuery scripts just before the closing body HTML tag in CakePHP 2.2.2

In your view file app/View/Controller/view.ctp…

Login

Blog History

In your view file app/View/Controller/view.ctp or at the top of your layout app/View/Layouts/layout.ctp put

$this->Html->script(
    'jquery.min', 
    array(
        'inline' => false, 
        'block' => 'script_bottom'
    )
);
# or multiple scripts
$this->Html->script( array(
         'jquery.min', 
         'slider'
    ), 
    array(
        'inline' => false, 
        'block' => 'script_bottom'
    )
)

In your layout file app/View/Layouts/default.ctp

	</div>
	<?php echo $this->element('sql_dump');
		echo $this->fetch('script_bottom'); ?>
</body>
</html>

Outputs something like this:

<script type="text/javascript" src="/dev/cakephp-nodb/js/arbitrary_script_name.js"></script></body>
</html>

The script or scripts needs to be copied into app/webroot/js

script_bottomĀ is a block name that you make up.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.