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

Written by James McDonald

September 24, 2012

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 *

You May Also Like…

How to Research a CPU Upgrade

How to Research a CPU Upgrade

Upgrade Time! Doing a lot of VMWare Workstation virtualization to create labs for self-study and training. Finding...