Conflict on templates view of custom lists in Sharepoint

0

Problem

I have two custom lists with ListTemplateType = 100 . When I insert the two on a page the last overwrites the first one, then it stops working, only the last one works.

I tried to add BaseViewID with different ID's to both, as I saw in this question . But now neither template is working. Before only the latter did not display anything, now both are displaying the default Sharepoint listing.

Template 1 app1-jslink.js

;(function(){
    overrideCtx.Templates.Header = "<div id='gallery-cardapio'>"+
            "<div class='gallery-cardapio'>"+
                "<ul class='thumbs'>";
    overrideCtx.Templates.Footer = CustomFooter;
    overrideCtx.BaseViewID = 1000;
    overrideCtx.ListTemplateType = 100;

    overrideCtx.Templates.Item = CustomItem;

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);

    function CustomItem(ctx){...}

    function CustomFooter(ctx){...}
})();

Template 2 app2-jslink.js

;(function(){
    overrideCtx.Templates.Header = "<div id='gallery-niver'>"+
            "<div class='gallery-container'>"+
                "<ul class='thumbs'>";
    overrideCtx.Templates.Footer = CustomFooter;
    overrideCtx.BaseViewID = 900;
    overrideCtx.ListTemplateType = 100;

    overrideCtx.Templates.Item = CustomItem;

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);

    function CustomItem(ctx){...}

    function CustomFooter(ctx){...}
})();

Testing

If I put BaseViewId in only one, both templates will be rendered with override that does not have BaseViewId .

If I put BaseViewId in both, they will be rendered with the default Sharepoint listing template.

If I do not set BaseViewId to none, both will be rendered with the last override .

How to solve this problem?

    
asked by anonymous 01.06.2015 / 16:25

1 answer

1

I solved the problem as follows:

I added a webpart of type editor on the page with the following code:

<script type="text/javascript">
    ExecuteOrDelayUntilScriptLoaded(function(){

        var oldRenderListView = RenderListView;

        RenderListView = function(ctx,webPartID) {
            if (ctx.wpq == 'WPQ5')
                ctx.BaseViewID = 900;
            else if (ctx.wpq == 'WPQ6')
                ctx.BaseViewID = 1000;

            oldRenderListView(ctx,webPartID);
        }

    },"ClientTemplates.js");
</script>

The function runs after the ClientTemplates.js script has been loaded. It overwrites BaseViewId of my templates that have the WPQ5 and WPQ6 codes.

Sources

01.06.2015 / 23:03