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.

Gaurravs
  • 3,558
  • 12
  • 22
  • 33
Dave
  • 617
  • 1
  • 7
  • 22

1 Answers1

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();
});
Danny '365CSI' Engelman
  • 21,176
  • 7
  • 35
  • 79