2

This is my second display template, which is mostly a copy of the first one. All of the configurations are the same, but for some reason it's not firing when the page is loaded.

here is the configuration within the masterpage gallery

enter image description here

within the webpart configuration, this is the url that I'm using

 ~sitecollection/_catalogs/masterpage/block_release_form.js

here is the code

(function () {
var blockReleaseFormFieldCtx = {};

// Define template variable     
blockReleaseFormFieldCtx.Templates = {};


// Define your required fields and functions to call in each case.
blockReleaseFormFieldCtx.Templates.Fields = {
    "BCD2": {
        "View": BlockReleaseFormViewTemplate
    },

};

// Register the template override with SP2013 
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(blockReleaseFormFieldCtx));
})();

function BlockReleaseFormViewTemplate(ctx) {
var _blockCreatedDate = ctx.CurrentItem.BCD2;
var _approvedHours = ctx.CurrentItem.ApprovedHours;

// View must contain the columns used
//if(_blockCreatedDate == 'undefined' || _approvedHours == 'undefined'){
//  return '';
//}

if (_blockCreatedDate >= "21" )
{
    return "<div style='background-color: #B5BBFF; width: 100%; display: block; border: 2px solid #2500DE; padding-left: 2px;'></div>";
    //return alert("We are 21");
}
else if (_blockCreatedDate <= '21')
{
    return "<div style='background-color: #FFB5B5; width: 100%; display: block; border: 2px solid #DE0000; padding-left: 2px;'></div>";
}    
}
  • What are you attaching the display template code to? And is it on the same object that you attached your first display template to? – Dylan Cristy May 19 '15 at 20:43
  • Attaching this to the list view (allitems.aspx). This is a different site collection/list from the first display template. – Jason May 19 '15 at 21:12
  • Did you debug? Is there breakpoint hitting on it? Try publishing the file and check. – Pradip R. May 19 '15 at 21:42
  • what would be the best way to debug? I'm looking at the source tab in Chrome dev tools, and I'm not seeing the script file – Jason May 19 '15 at 21:53
  • If you're not seeing the script file, it may not be loading. Is the site collection this is supposed to be used for the root site of the web application? (i.e. the site collection URL is http: //my.server.name/) I have never set up a display template with a target scope as broad as /. Maybe try specifying something more specific for the target scope, like /sites/sitecollectionName? (Or whatever the URL is to this particular site collection.) – Dylan Cristy May 20 '15 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.