0

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?

1
+100

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....

  • webId is undefined. I'm using SP 2013 on prem and from the screen shots I think you're using something newer? Any idea where else I can get that ID? – Rothrock Jun 6 at 15:33
  • On which page are you running to web id? That object is available on so 2013 on prem also – Siddharth Vaghasia Jun 6 at 16:43
  • It was undefined on all the pages -- at least as part of the _spPageContextInfo. But I was able to get it at the REST endpoint <site>/_api/web/id – Rothrock Jun 6 at 17:02
  • Ok..you can always use Spinsider chrome extension.. it is great extension to quickly try rest api from browser itself – Siddharth Vaghasia Jun 6 at 17:13
  • I've accepted this as the answer, but I can't award the points yet. – Rothrock Jun 6 at 20:24

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.