2

Bit stumped on this one, wonder if anyone can help?

I've created some JavaScript which is stored in the Style Library and referenced by the JSLink property of a site column. When I navigate to a document library that includes the site column in its default view, the JSLink code does not appear to fire (tested using the line that writes to the console).

When I refresh the page however, the JSLink code fires and the image link is rendered for each item in the view. Why doesn't this code fire on the initial page load, but only on page refreshes?

(function () {
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Fields = {
    'SiteColumnInternalName': {
        'View': function (ctx) {
    // write to the console so we know whether or not the render code has run
    if (console != undefined) console.log("Render code hit");
            return "<a href='" + ctx.HttpRoot + "/_layouts/somefolder/somepage.aspx?List=" +
                    ctx.listName.replace('{', '').replace('}', '') + "&ID=" + ctx.CurrentItem.ID + "'>" +
                        "<img src='" + ctx.HttpRoot + "/Style%20Library/img/someimage.gif'/>" +
                    "</a>";
        }
    }
};    
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);})();

2 Answers 2

3

Check out how this JavaScript is run with the minimal download option enabled.

Take the code sample and replace the address at the bottom with where you placed the JSlink file and give it a spin.

http://code.msdn.microsoft.com/office/SharePoint-2013-Folder-661709eb

0

I found the answer in the following link: http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/ca160c8a-b814-45e8-a9e3-6a4a4d768efa

MS added an SPWeb scoped feature called 'Minimal Download Strategy' to SharePoint 2013 which appears to break JSLink rendering (except for on page refreshes). Disabling the feature fixed the JSLink rendering!

7
  • 1
    just to let you know, I am successfully using JSLink on sites with Minimal Download Strategy activated. Commented Jun 10, 2013 at 13:16
  • Perhaps I'm missing a SP update on my dev server... Were you using JSLink successfully on a Field or for something else (i.e. list view/web part)? Thanks
    – SPQuestion
    Commented Jun 10, 2013 at 14:19
  • Both on a field and in an XSLT list view webpart :) Commented Jun 10, 2013 at 14:20
  • Did you use RegisterModuleInit()? blogs.msdn.com/b/sridhara/archive/2013/02/08/…
    – SPQuestion
    Commented Jun 10, 2013 at 20:49
  • 1
    Ok, thanks for your feedback - hopefully I'll get a chance to test both the _layouts approach and the RegisterModuleInit() approach and see if either or both work for me (with MDS enabled), as this would be preferable to disabling the feature. Thanks
    – SPQuestion
    Commented Jun 12, 2013 at 9:53

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.