0

Is there a way to include another .JS file into a JSLink file?

I have made mini framework to render list views which I want to source out in a seperate file and then add a normal JSLink file for every list to customize it.

But it's not working if I add it to my normal global .JS files, since the JSLink files seemed to be loaded quite early in the loading process and my custom framework class is not loaded then.

1 Answer 1

6

Make JSlink load your file

You can put multiple files in the JSlink where you now use:

~sitecollection\....\yourCSRfile.js

They have to be separated by a ; (semi-colon)

They do not have to be CSR files, can be any JS file (It is called JSlink for a reason).
But they have to be in a location where JSlink may access them: ~site or ~sitecollection (and more)

(Note: SharePoint Online allows linking to ANY https:// URI !!)

There used to be great info at:
http://spdevlab.com/2013/07/07/5-facts-about-jslink-in-sharepoint-2013-you-might-not-know/

But it seems someone forgot to pay the bill for SPdevlab.com

Update 1

Here's one that remembered to pay the bills..

https://www.martinhatch.com/2013/08/jslink-and-display-templates-part-1.html

Update 2 - Re: comment

If you want one JSfile and your code depends on NYL (not-yet-loaded) (external) JS libraries you need to look into SOD (Script On Demand) and execute your code after they have loaded:

Update #3 SOD at work:

SP.SOD.registerSod('iCSR', '/xyz/iCSR_GenericLibrary.js');
SP.SOD.executeFunc('iCSR', null, function () {
    console && console.info('Loaded dependencies');
    var csrfile="~siteCollection/Style Library/THISCSRFILE.js";
    RegisterModuleInit(SPClientTemplates.Utility.ReplaceUrlTokens(csrfile), init);
    init();
});
2
  • Yes, I know that you can add serveral JSLink files. But I was hoping to make it easier for collegues of mine, to use this solution by adding just one single file.
    – Dave
    Commented Nov 23, 2015 at 12:51
  • Added update #2 to answer Commented Nov 23, 2015 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.