Yes, you just have to change your syntax a little:
define( function( require ){
var path = 'json!/app/pagelang/login';
require([path], function(appLang){
// Do stuff with appLang…
});
});
Question
Is it possible to do this:
define( function( require ){
var path = 'json!/app/pagelang/login';
var appLang = require(path),
instead of this:
define( function( require ){
var appLang = require('json!/app/pagelang/login'),
from my tests it's not possible because it results on the following console error:
Uncaught Error: Module name "json!/app/pagelang/login_unnormalized2" has not been loaded yet for context: _
Solution
Yes, you just have to change your syntax a little:
define( function( require ){
var path = 'json!/app/pagelang/login';
require([path], function(appLang){
// Do stuff with appLang…
});
});
OTHER TIPS
The answer is actually "no", your second snippet uses sugar syntax which uses regular expressions to rewrite your code "behind the scenes" to be something like:
define(['json!/app/pagelang/login'], function (appLang) {
// appLang available
});
The same mechanism can't work when the module name is a variable because the dependencies block needs concrete module names, not variables. Because of that, as noted by @idbehold you need to use a proper asynchronous form of inlined require
:
define(function (require) {
var path = 'json!/app/pagelang/login';
require([path], function (appLang) {
// appLang available
});
});