0

I have 1 list that I want to display in 2 different ways on the same page. When using the jslink property included in the OOTB listview webpart only one display template gets rendered for both webparts.

I'll use some example code from a blog post by Wes Preston, if anyone could show an example of how 2 of these display templates can be used together I can work from there.

template 1:

(function () {

//   Initialize the variables for overrides objects
    var overrideCtx = {};
    overrideCtx.Templates = {};

//  alert("Override call worked");

//  Use BaseViewID and ListTemplateType to narrow focus/scope on 
//  which web parts on the page are affected
//  overrideCtx.BaseViewID = 1;
//  overrideCtx.ListTemplateType = 100;

    /*
     * Using the Fields override leaves the rest of the rendering intact, but 
     * allows control over one or more specific fields in the existing view
     */
    overrideCtx.Templates.Fields = {
        'MoreText': { 'View' : 'Animal' }
    };

    /*
     * Register the template overrides.
     */
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

template 2:

(function () {

//   Initialize the variables for overrides objects
    var overrideCtx = {};
    overrideCtx.Templates = {};

//  alert("Override call worked");

//  Use BaseViewID and ListTemplateType to narrow focus/scope on 
//  which web parts on the page are affected
//  overrideCtx.BaseViewID = 1;
//  overrideCtx.ListTemplateType = 100;

    /*
     * Using the Fields override leaves the rest of the rendering intact, but 
     * allows control over one or more specific fields in the existing view
     */
    overrideCtx.Templates.Fields = {
        'MoreText': { 'View' : '<b><#=ctx.CurrentItem.MoreText#></b>' }
    };

    /*
     * Register the template overrides.
     */
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

Thanks.

1

You need to set the BaseViewID properties to different values, such as 99 and 98. See this blog for more info.

Your Answer

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

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