Reputation: 116373
I'm using the text
plugin of RequireJS. Is it possible to reference a text file in the path configuration file? I've tried
require.config({
paths: {
'myTemplate': 'text!templates/myTemplate.html'
}
});
but that didn't work.
Upvotes: 5
Views: 2195
Reputation: 10408
RamenRecon's answer helped, but in my case I think it was slightly confusing by using myTemplate for the path and template name. The key I found is to only substitute the Path, but not the actual file name. As a result, to abstract the path to /subSystem/templates/myTemplate.htm using require and the path configuration, set the configuration as follows:
require.config({
paths: {
templatePath: 'subsystem/templates'
}
});
And then in your module definition:
define(['text!templatePath/myTemplate.htm'],
function(template) {}
);
Upvotes: 4
Reputation: 1882
The reason it isn't working is because RequireJS plugins are designed to be used as part of a require command, not in the config.
Try:
require.config({
paths: {
'myTemplate': 'templates/myTemplate.html'
}
});
and in your module:
define(
['text!myTemplate'],
function () {}
)
Upvotes: 7