Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text files in the path configuration file

Tags:

requirejs

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.

like image 485
Randomblue Avatar asked Jan 08 '12 20:01

Randomblue


People also ask

Is a config file a text file?

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.

What is configuration file path?

C:\Program Files\Common Files\FotoWare. Configuration files.

How do I get the file path of a text file?

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).

What is the config text file?

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.


2 Answers

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 () {}
)
like image 85
Matt S Avatar answered Nov 12 '22 11:11

Matt S


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) {}
);
like image 4
Jim Wooley Avatar answered Nov 12 '22 11:11

Jim Wooley