SharePoint JSLink Display Templates

Links

Sample Code

Sample JavaScript code for a JSLink template.

(function () {
    var oCtx = {};
    debugger;
    oCtx.Templates = {};
    oCtx.Templates.Fields = {};
    oCtx.Templates.Fields.Course = { 'View' : '<div style="min-width:100px;"><#=courseFormat()#></div>' };

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(oCtx);
})();

function courseFormat() {
    var course = ctx.CurrentItem.Course;
    var values = new Array(course.length);

    for (var i = 0; i < course.length; i++) {
        values[i] = course[i].Label;
    }

    return values.join('<br>');
}

function course1Format() {
    var course = ctx.CurrentItem.Course1;
    var values = new Array(course.length);

    for (var i = 0; i < course.length; i++) {
        values[i] = course[i].Label;
    }

    return values.join('<br>');
}

Leave a Reply

Your email address will not be published. Required fields are marked *

three × four =