JSLink Wont Render

I am trying to deploy the below code. I am just trying to figure out how to render JS Link code.

<script src="http://pastebin.com/embed_js.php?i=SBbvpMGA"></script>

I have put the JS in the master page gallery with the following meta data.

When I try to reference the JS in the list view web part on the page I referenced above in the target scope nothing renders.

~site/_catalogs/masterpage/HF.js.

I also tried ~sitecollection for good measure and it did not work.

I am totally confused as to what the problem may be at this point.


September 3rd, 2015 12:14am

Hi,

The following steps for your reference:

1. Save the code below as a js file(HF.js).

(function(){
var overrideContext = {};
overrideContext.Templates = {};
overrideContext.Templates.Item = overrideTemplate;
overrideContext.Templates.Header = overrideHeader;
overrideContext.Templates.Footer = overrideFooter;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);
})();
function overrideHeader(){
        return "<h2>Head Text</h2>"
};
function overrideFooter(){
       return "<h2>Footer Text</h2>"
};
function overrideTemplate(ctx) {
    var title = ctx.CurrentItem["Title"];
    return "<h2>" + title + "</h2>";
}

2. Upload the js file into the Site Assets library.

3. Reference the js file in the list view web part using this:

~site/SiteAssets/HF.js

Best Regards,

Dennis

Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 7:02am

So I followed what you did step by step and it was not working in Office 365. I then went and tried it on my on prem installation and it worked.

Any idea why it isnt working with SharePoint Online?

Also, Why is the overrideHeader() and overrideFooter() dependent on a override Template function?


September 3rd, 2015 8:56am

Hi,

If you use the JSLink in a subsite in SharePoint Online, please try to use "~sitecollection/SiteAssets/HF.js". It also works in my SharePoint Online environment.

Best Regards,

Dennis

Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 9:30pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics