Question

We are using the page publishing features and I'm trying to put together a custom page layout that includes a list view of the pages library.

I've gone into the Snippets gallery but there isn't a choice to create a list view snippet.

I found this thread. But don't understand the answers. Some of the answers there seem to be for SP Online and we are using SP 2013. The second one says to put this code in a webpart zone

<WebPartPages:XsltListViewWebPart ID="XsltListViewWebPart2" 
    runat="server" ListUrl="Lists/PublicDocuments" IsIncluded="True" 
    NoDefaultStyle="TRUE" Title="Public Documents" PageType="PAGE_NORMALVIEW" FrameType="None"
    Default="False" ViewContentTypeId="0x"> 
</WebPartPages:XsltListViewWebPart>

I used the custom ASP.NET markup feature in the snippets gallery and change the url to point to the pages library.

<!--CS: Start Create Snippets From Custom ASP.NET Markup Snippet-->
<!--SPM:<WebPartPages:XsltListViewWebPart ID="XsltListViewWebPart2" 
    runat="server" ListUrl="Pages" IsIncluded="True" 
    NoDefaultStyle="TRUE" Title="Pages" PageType="PAGE_NORMALVIEW" FrameType="None"
    Default="False" ViewContentTypeId="0x"> -->
<!--SPM:</WebPartPages:XsltListViewWebPart>-->
<!--CE: End Create Snippets From Custom ASP.NET Markup Snippet-->

In the design manager preview for the page layout this works, except it shows the page library for the site collection level and not the subsite. When I try and create a page with this webpart on it I get an error. If I change the url to try and direct to the subsite it doesn't even work in the preview.

List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user.

Additionally I need to configure a lot of the properties for the list view and don't know what they are called, so a version of this with the properties would be helpful

It seems to me that a page with a list view is kind of an important thing that should be easy and pretty much needed all the time, yet I can't find anything on line that actually shows how to do it.

How can I create the right kind of markup to add to our pagelayout html to show the pages library?

Was it helpful?

Solution

You have to use WebId property in webpart snippet to get data from specific subsite. By specifying webid property it will try to find Pages library from web id and display data from subsite rather than Site collection. below is updated snippet on how to display from subsite.

<!--CS: Start Create Snippets From Custom ASP.NET Markup Snippet-->
<!--SPM:<WebPartPages:XsltListViewWebPart ID="XsltListViewWebPart2" 
    runat="server" ListUrl="Pages" IsIncluded="True" WebId="{613454a5-7010-4983-afab-a85a8f5d6067}"
    NoDefaultStyle="TRUE" Title="CustomList" PageType="PAGE_NORMALVIEW" FrameType="None"
    Default="False" ViewContentTypeId="0x"> -->
<!--SPM:</WebPartPages:XsltListViewWebPart>-->
<!--CE: End Create Snippets From Custom ASP.NET Markup Snippet-->

To Get WebId of subsite, you can do following.

visit subsite, open chrome developer tool and go to console and use type below

_spPageContextInfo.webId

You will get below output

enter image description here

Now create a page from your custom page layout you would see data coming from subsite rather than site collection. With this, it will make sure data is always coming from particular subsite.

Below is screenshot of page layout preview showing data from subsite pages library

enter image description here

Below is screenshot of page created in subsite via custom page layout. 'en-us' is my subsite

enter image description here

Regarding "Additionally I need to configure a lot of the properties for the list view and don't know what they are called" You can refer this link to know about all the additional properties available with list view webpart. For more details about each property and its supported value, it would be best to google about required property and add accordingly.

Hope this helps....

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top