Written by James McDonald

October 6, 2011

I read the documentation. But I must be a slow learner or something.

Anyway including javascript into a view using cakephp:

I am using an auto baked cake template named index.ctp

For me it’s located cake_app_dir/views/names/index.ctp

To get the javascript script block into your page I needed to add the following in the index.ctp page:

< ?php $this->Html->script(array ( 'jquery', 'script2', 'script3'), false);?>

Where the array contains the name of the javascript file sans the dot js extension of each file on you want to include

You can create custom locations for javascript under webroot e.g.

mkdir -p cake_app_dir/webroot/test/one/two

Put your javascript into the custom dir and specify the path as follows

< ?php $this->Html->script(array ( 'jquery', 'script2', 'script3', '/test/one/two/script4.js' ), false);?>

specifying false tells it to output the block where the $scripts_for_layout echo statement is in cake_app_dir/views/layouts/default.ctp

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...