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 *

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.

You May Also Like…

Squarespace Image Export

To gain continued access to your Squarespace website images after cancelling your subscription you have several...

MySQL 8.x GRANT ALL STATEMENT

-- CREATE CREATE USER 'tgnrestoreuser'@'localhost' IDENTIFIED BY 'AppleSauceLoveBird2024'; GRANT ALL PRIVILEGES ON...

Exetel Opt-Out of CGNAT

If your port forwards and inbound and/or outbound site-to-site VPN's have failed when switching to Exetel due to their...