0

I have a javascript code that should only run in app/Clients/show_products.ctp

$(document).ready(function(){ //Do stuff }); 

Should I to put this in layout or in the end of the view?

1 Answer 1

2

Put it in the app/Clients/show_products.ctp view, using scriptBlock

$this->Html->scriptBlock(' $(document).ready(function(){ //Do stuff }); '); 

You can specify to display the code inline or not. If you need it in more than one places, you can use an element

Adding it on the bottom of the view would be ok.

If you have a lot of code, it's better to create a js file for it.

Sign up to request clarification or add additional context in comments.

2 Comments

Anywhere in the view should be a good practice, or should I put this in the end of the view? thanks
I added a few more notes to the answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.