1

im trying to link a bootstrap js file and css file to Cakephp 3x

<?= $this->Html->css('bootstrap') ?> <?= $this->Html->css('bootstrap-theme') ?> 

i use this code to src/Template/Layout/default.ctp and the css file is working but when i try to link the js with the same approach

<?= $this->Html->script('jquery') ?> <?= $this->Html->script('bootstrap') ?> 

the problem is the Js is not working, thank you for your response

3 Answers 3

1

You can include js like this

 <?= $this->Html->script('https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js') ?> 

Or if your js file exist in your project then it must be in webroot/js folder then you can include file like this

 <?= $this->Html->script('custom.js') ?> 
Sign up to request clarification or add additional context in comments.

1 Comment

dont forget to upvote and accept answer if its helpful for you :) .
0

place all css files inside webroot/css folder and js file inside webroot/js

and access the files like this in view files

<?= $this->Html->css('owl.carousel');?> <?php echo $this->Html->script('jquery.plugin') ?> 

if you want to place all assets in some other folder like css, js, pugin etc create a folder assets or anything else that you want and place all the folder inside it use structure like this

webroot/assets/css/ webroot/assets/js/

you can access the files like this in view files

<?= $this->Html->css('/assets/css/owl.carousel');?> <?php echo $this->Html->script('/assets/js/jquery.plugin') ?> 

remember the slash before assets

Comments

0

You can use:- $this->Url->build('/'); // this refer till webroot folder. after that your folder path and js or css file name.

Example:-

<a href="<?php echo $this->Url->build('/'); ?>js/your_js_file.js"></a> <a href="<?php echo $this->Url->build('/'); ?>css/your_css_file.css"></a> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.