Conflict in custom list view templates in Sharepoint

Asked

Viewed 39 times

0

Problem

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

I tried to add the BaseViewID with different ID’s for both, as I saw in this question. However, now neither of the two templates is working. Before only the last showed nothing, 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 the BaseViewId in just one, both of them templates will be rendered with the override who does not own the BaseViewId.

If I put the BaseViewId both of them will be rendered with the standard Sharepoint listing template.

If I don’t put BaseViewId neither, both will be rendered with the last override.


How to solve this problem?

1 answer

1

I solved the problem as follows:

I added a webpart editor-type script 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 is executed after the script ClientTemplates.js have been loaded. It overwrites the BaseViewId of my template containing the codes WPQ5 and WPQ6.

Sources

Browser other questions tagged

You are not signed in. Login or sign up in order to post.