Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);})();
share|improve this question
add comment

2 Answers 2

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

share|improve this answer
add comment

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!

share|improve this answer
    
just to let you know, I am successfully using JSLink on sites with Minimal Download Strategy activated. –  Robert Lindgren Jun 10 '13 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 Jun 10 '13 at 14:19
    
Both on a field and in an XSLT list view webpart :) –  Robert Lindgren Jun 10 '13 at 14:20
    
Did you use RegisterModuleInit()? blogs.msdn.com/b/sridhara/archive/2013/02/08/… –  SPQuestion Jun 10 '13 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 Jun 12 '13 at 9:53
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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