1

One of my SharePoint List running on SharePoint 2013 has a Content Editor WebPart which is mapped to a Javascript file.

If I save the SharePoint List as a Template, will it store the Content Editor WebPart information too along with location of the Javascript File.? If not, what is the best way so the List is aware of the JS file?

3 Answers 3

1

Lists are displayed with WebParts

So SharePoint 2013 CAN attach JavaScript files to Lists.

JSLink

It is the JSLink setting in the Misc section of the WebPart properties

Be aware, unlike a CEWP script, this JSLinked scriptfile will load before the whole page is loaded. So if you do DOM related stuff you need to wait till the DOM is there

With code you can also set JSLinks on Views if you want

Now.. when people say 'JSLink' they often mean:

CSR = Client Side Rendering

Is Microsofts way of letting you override the HTML code that is used to display View, Forms etc.
So this gives you a hook into SharePoints HTML before the whole page is created.

You do not have to CSR.. JSLinks can link to any JavaScript file

iCSR - http://iCSR.github.io

Is a JS library which makes CSR development a bit easier

There is a link to a slidedeck on the page which explains the lot (you need basic understanding of HTML/JavaScript)

There is also a link to the free "LinkManager" Bookmarklet which lets you set JSLinks on WWebParts and Views with a GUI instead of 10 clicks in WebPart Properties

0

It won't save it in the template! There is no way you can attach a JS to a list, unless you create a solution with a feature that will deploy a JS file and the content editor WP

0

It will not store the JS scripts if you are deploying it via a Content Editor Web part , To have your scripts stored in the list template, Write it directly on the Newform.aspx page or EditForm.aspx page under tag in SharePoint Designer.

Once you have the pages with the scripts, you can store it as a template and can have the javascripts along with it. Make sure you have a generalized JS scripts not dependent on features outside list or that site collection.

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.