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.
CONFIG file extension is a configuration file used by various programs to store settings that are specific to their respective software. Some configuration files are plain text files but others might be stored in a format specific to the program.
C:\Program Files\Common Files\FotoWare. Configuration files.
Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).
A configuration file, often shortened to config file, defines the parameters, options, settings and preferences applied to operating systems (OSes), infrastructure devices and applications in an IT context.
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 () {}
)
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) {}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With