Can't find an example for implementation of jquery


In older apps I used the JS-Helper.
What is the right way in 3.3 for the sortable jquery example?
I’m searching for hours now, but the ‘how to include the javascript - jquery code in cakephp 3.3’ I can’t find :frowning:


to include for all pages

copy jquery.min.js to webroot/js/jquery.min.js



echo $this->Html->script([


That’s like before. But how can I write the $( “my.button” ).html( “Next Step…” ) in files?

in model template:

   $(document).ready(function() {
        $( "my.button" ).html( "Next Step..." );

    ', ['block' => true]);


That’s it! Many Thanks.


I prefer to move the JavaScript into an Html-helper-element. So I don’t mess up my template with large JavaScript-Codeblocks and can reuse the JavaScript-code in other templates.

For example:
In your template-file:

<?php $this->append('script'); echo $this->element('js/typeaheadUsers'); $this->end(); ?>

in /src/Template/Element/js/typeaheadUsers.ctp:
< script>
$(document).ready(function () {

< / script>

Another advantage is that the code-highlighting and code-formating of your IDE (if you use one) is working.