3

function myCSRtemplate( ctx )

All CSR examples out there only pass the ctx object to the template function:

FieldContext.Templates = {};
FieldContext.Templates.Fields = {
    "myColumn": {
        "View": myCSRtemplate
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(FieldContext);

function myCSRtemplate(ctx){
    var name = ctx.CurrentFieldSchema.Name;
    var value = ctx.CurrentItem[name];
    var ID = ctx.CurrentItem.ID;
}

Is this a remnant of some early blogs because the Form overrides only receive one parameter?

function myCSRtemplate(ctx, CurrentFieldSchema, CurrentItem, ListSchema)

Is there another reason why we are all not using the default 2nd, 3rd and 4th parameter SharePoint passes into the function (for View templates)?

function myCSRtemplate(ctx, CurrentFieldSchema, CurrentItem, ListSchema){
    var name = CurrentFieldSchema.Name;
    var value = CurrentItem[name];
    var ID = CurrentItem.ID;
}

TIA

Danny

ICSR

3
  • Not sure what you are aming at, but are not those properties also available in the ctx object? Making it a "do what you like" thing? :) Commented Jul 19, 2015 at 13:56
  • I guess also must of the blogs around are quite easy proof-of-concept implementations not really using those variables Commented Jul 19, 2015 at 14:14
  • I wondered if there was an issue with those extra existing variables; even the MSDN examples do not use them. Commented Jul 20, 2015 at 20:38

1 Answer 1

0

Answering my own question to get it out of the un-answered list

Yes, the View Template functions get 4 parameters

Perfectly valid to use them

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.