6

GOAL: I am trying to create a custom page layout based on a custom content type that contains 3 xsltlistviewwebparts which use custom views that were created for the lists in the browser.

I have successfully created the page layout from my content type, and added the 3 xsltlistviewwebparts to it.
In my html file I have the following snippet:

<!--SPM:<WebPartPages:XsltListViewWebPart ID="XsltListViewWebPart4" 
runat="server" IsIncluded="True" 
NoDefaultStyle="" Title="Pages/Contacts" FrameType="Default"
ViewContentTypeId=""
DisplayName="Contacts"
ViewGuid="{3D3974A3-AC3A-4284-9F1A-2F99DB986FF9}"
ListUrl="" ListDisplayName="" ListName="{F8BDEC5F-666F-405C-97E2-EF658DBA1DFB}" ListId="f8bdec5f-666f-405c-97e2-ef658dba1dfb"
AllowZoneChange="False" AllowEdit="False"
DisableSaveAsNewViewButton="TRUE" DisableViewSelectorMenu="TRUE" > -->
<!--SPM:</WebPartPages:XsltListViewWebPart>-->

ISSUE: I need this web part to use a custom view that I created for the list, but no matter what I try SharePoint uses the default view for the list when it translates the html snippet to aspx.

  • I tried setting ViewGuid property in the snippet, but it didn't work.
  • I tried saving a webpart that had the view already defined to the webpart gallery and adding that to the layout, but SharePoint still used the default view when it translated the snippet.
  • I tried explicitly setting the view definition in the snippet, but SharePoint overwrote it when it translated the snippet.
  • I tried just editing the translated aspx file to save time, but it ended up breaking the server and it doesn't seem like a good practice.

I've been playing around with javascript and trying to get it to change the view using the client side object model, but I have almost no experience with javascript and I know there has to be some way to set the view in the html snippet.

QUESTION: Is it actually possible to tell a xsltlistviewwebpart to use a custom view from the html snippet in the page layout html file? If so, how?

4

This might classify as more of a work-around than a solution, but I used the guid of the view as the webpart id.
I decided to look into the content database to see how views are stored. In the stored procedure proc_CreateView I found that views are actually stored in the AllWebParts table with the ViewId inserted into the tp_ID column.
So I added the following to my snippet:

__WebPartId="{3D3974A3-AC3A-4284-9F1A-2F99DB986FF9}"

Now my snippet looks like this:

<!--SPM:<WebPartPages:XsltListViewWebPart
ID="XsltListViewWebPartContacts" 
runat="server" IsIncluded="True" 
NoDefaultStyle="" Title="Contacts" FrameType="TitleBarOnly"
ViewContentTypeId="" InplaceSearchEnabled="False"
DisplayName="Contacts" ChromeType="TitleOnly"
ViewGuid="{3D3974A3-AC3A-4284-9F1A-2F99DB986FF9}"
ListUrl="" ListDisplayName="" ListName="{F8BDEC5F-666F-405C-97E2-EF658DBA1DFB}" ListId="f8bdec5f-666f-405c-97e2-ef658dba1dfb"
AllowZoneChange="False" AllowEdit="False"
DisableSaveAsNewViewButton="TRUE" DisableViewSelectorMenu="TRUE" 
__WebPartId="{3D3974A3-AC3A-4284-9F1A-2F99DB986FF9}" > -->
<!--SPM:</WebPartPages:XsltListViewWebPart>-->

The new property is set at the very end of my snippet.

NOTE: I am still setting the ViewGuid property. If the ViewGuid is not set, I get the following error:

Error message

NOTE: The guid for the view can be found on edit view page in either the URL bar or in the mobile section where it says "Web address for this mobile view:" and then gives a URL. For me the URL bar had:

~siteUrl/_layouts/15/ViewEdit.aspx?List=%7BF8BDEC5F-666F-405C-97E2-EF658DBA1DFB%7D&View=%7B3D3974A3-AC3A-4284-9F1A-2F99DB986FF9%7D&...(some other URL parameters the form uses)

and the mobile URL had:

~siteUrl/_layouts/15/mobile/viewa.aspx?List=f8bdec5f%2D666f%2D405c%2D97e2%2Def658dba1dfb&View=3d3974a3%2Dac3a%2D4284%2D9f1a%2D2f99db986ff9

DO NOT FORGET TO REPLACE THE HEX CODES WITH THEIR SPECIAL CHARACTERS!!!! For me, in the URL bar I had to take out the "%7B" (the "{" character I believe) at the beginning of the guid and the "%7D" (the "}" character I believe) at the end of the guid, and in the mobile URL I had to replace every "%2D" with the "-" character.

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.