Note that there are some explanatory texts on larger screens.

plurals
  1. PORequireJS using path in other file
    text
    copied!<p>I have a site developed in cakephp, backbone and requirejs.</p> <p>Into my config file I have mapped my javascript and if I called jquery into this file all works fine. If i call jquery into another file give me error that function is indefined like that jquery isn't loaded.</p> <p>This is my fole that works fine config.js:</p> <pre><code>require.config({ baseUrl: "/site.com/js/", paths: { // Aliases for libraries, so that we can change versions from here jquery: "libs/jquery/jquery-2.0.2.min", handlebars: "libs/backbone/template/handlebars", lodash: "libs/backbone/template/lodash.min", backbone: "libs/backbone/backbone-1.0.0.min", less:"libs/less/less-1.4.0-beta.min", helper:"app/helper", jquery_cookie:"libs/jquery/plugin/jquery.cookie", text:"libs/require/text-2.0.7" }, shim: { "lodash": { exports: '_' }, "handlebars": { exports: 'Handlebars' }, "jquery": { exports: '$' }, "backbone": { //These script dependencies should be loaded before loading //backbone.js deps: ["helper", "lodash", "jquery"], //Once loaded, use the global "Backbone" as the //module value. exports: "Backbone" }, "jquery_cookie": { deps: ["jquery"] //,exports:"$" }, "less": { exports:"less" } } // This is appended to every module loading request, for cache invalidation purposes // comment it on production , urlArgs: "bust=" + (new Date()).getTime() }); require(["jquery"], function ($) { $("body").empty(); }); </code></pre> <p>Instead if I write this into config.js</p> <pre><code>require.config({ baseUrl: "/site.com/js/", paths: { // Aliases for libraries, so that we can change versions from here jquery: "libs/jquery/jquery-2.0.2.min", handlebars: "libs/backbone/template/handlebars", lodash: "libs/backbone/template/lodash.min", backbone: "libs/backbone/backbone-1.0.0.min", less:"libs/less/less-1.4.0-beta.min", helper:"app/helper", jquery_cookie:"libs/jquery/plugin/jquery.cookie", text:"libs/require/text-2.0.7" }, shim: { "lodash": { exports: '_' }, "handlebars": { exports: 'Handlebars' }, "jquery": { exports: '$' }, "backbone": { //These script dependencies should be loaded before loading //backbone.js deps: ["helper", "lodash", "jquery"], //Once loaded, use the global "Backbone" as the //module value. exports: "Backbone" }, "jquery_cookie": { deps: ["jquery"] //,exports:"$" }, "less": { exports:"less" } } // This is appended to every module loading request, for cache invalidation purposes // comment it on production , urlArgs: "bust=" + (new Date()).getTime() }); </code></pre> <p>And move the call to jquery into the default.ctp retrieve me the error of function undefined because doesn't load the jQuery I think.</p> <p>default.ctp</p> <pre><code>require(["jquery"], function ($) { $("body").empty(); }); </code></pre> <p>Why I can't use jquery into deafult.ctp? I have to map into all files? I don't think so, can someone help me? Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload