Single Page Layout for Several Content Types
Just recently we came across a case where we needed to share a single page layout between three different content types. The visible meta data fields for all three content types were the same, and creating several identical page layouts felt wrong. Fortunately, SharePoint supports the scenario. Less fortunately, the documentation is a little sparse.
For a single page, your definition for page layouts might look something like this (I’m omitting most of the properties for brevity):
RootWebOnly="TRUE">
<File Url="Website.Publishing.aspx" Type="GhostableInLibrary">
<Property Name="PublishingAssociatedContentType"
Value=";#$Resources:res,ctype;<content type id>;#" />
</File>
</Module>
Suppose, now, that I want to use Website.Publishing.aspx for two content types. The solution is to point the Path attribute of the File element to the physical file, but provide separate, virtual file names that can be used to differentiate them:
RootWebOnly="TRUE">
<File Path="Website.Publishing.aspx" Url="Website.Publishing.aspx"
IgnoreIfAlreadyExists="TRUE" Type="GhostableInLibrary">
<Property Name="PublishingAssociatedContentType"
Value=";#$Resources:res,ctype;;<content type id>;#" />
</File>
<File Path="Website.Publishing.aspx" Url="Website.SomethingElse.aspx"
IgnoreIfAlreadyExists="TRUE" Type="GhostableInLibrary">
<Property Name="PublishingAssociatedContentType"
Value=";#$Resources:res,ctype;;<another content type id>;#" />
</File>
</Module>
Frankly, I’m not sure if the IgnoreIfAlreadyExists attribute is necessary, but I want to avoid any potential errors due to the file already existing. According to the documentation, if the file exists, it will be replaced, which is OK in this case, as it’s the same physical file.
This way, modifications made to the single file will propagate to both types of pages. Figuring this out wasn’t rocket science, but not exactly trivial either.
Popularity: 16% [?]
[...] Single Page Layout for Several Content Types (SharePoint Blues)Just recently we came across a case where we needed to share a single page layout between three different content types. The visible meta data fields for all three content types were the same, and creating several identical page layouts felt wrong. Fortunately, SharePoint supports the scenario. Less fortunately, the documentation is a little sparse. [...]
ipad games…
[...] iPad-Sense.nl – news – ipad games got really easy now that there is a new game [...]…
You have some bugs in html or css code in the footer.
Hi,
i tried to follow your solution but this always creates one page layout for each content type in the layouts gallery. i thought, this way i could associate one pagelayout with several content types, without having multiple layout files. is my understanding wrong and what i want is impossible with your solution?
Would be great to hear from you.
Best regards,
Jessica
Hi Jess,
It’s been a while since I did this, and I no longer have access to the project I was working on, so I may not remember things quite right. That said, I seem to recall that what you’re seeing is what I saw as well — basically, we’ve got multiple virtual URLs for the same page layout, so you’d see multiple pages in the gallery. The point of the exercise wasn’t to reduce the number of pages in the *gallery*, though, but rather to reduce the number of pages to maintain in the *solution code base*. In other words, updating the one layout file in the solution automatically propagated changes to all the three “virtual” layouts.
-Lauri