Single Page Layout for Several Content Types

April 21 2010 12 comments

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):

<Module Name="PageLayouts" Url="_catalogs/masterpage" Path="PageLayouts"
   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:

<Module Name="PageLayouts" Url="_catalogs/masterpage" Path="PageLayouts"
   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: 3% [?]

12 comments to “Single Page Layout for Several Content Types”

  1. [...] 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. [...]

  2. ipad kopen says:

    ipad games…

    [...] iPad-Sense.nl – news – ipad games got really easy now that there is a new game [...]…

  3. You have some bugs in html or css code in the footer.

  4. Jess says:

    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

  5. Lauri says:

    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

  6. Badek says:

    An fascinating dialogue is worth a comment. I ponder that it’s best to compose more by this subject, it may not be real a inviolable subject however commonly persons are not plenty to talk by such topics. To the next. Cheers

  7. Today, I went to the beachfront with my kids. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to
    her ear and screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is completely off topic but
    I had to tell someone!

  8. Edward greeg says:

    nice post you are very excited to being visiting your website can get what I was search for this acne no more book

  9. マークバイマークジェイコブストート
    Heya i am for the primary time here. I found this board and I find It truly helpful & it helped me out a lot.
    I hope to provide something back and help others such as you
    helped me.

  10. dave Zitting says:

    This type of financing, the applicant must be a first-time home buyer unlike PTT.
    The home owner can choose to receive the new, lower interest rate.
    In that case, your david g zitting mortgage will be paid
    to the heirs.

    Here is my blog :: dave Zitting

  11. I will at once seize a person’s feed because i won’t be able to to locate ones e-mail membership website link or perhaps e-newsletter services telefoonhoesjes. Have you got every? Remember to permit us understand so that I’ll subscribe. Thanks.

  12. Jamison says:

    Sharing different content types on the same page is a must for most pages, especially with modern websites like http://www.eriksvehicleremoval.ca/contact in 2023, so thanks for sharing this.

Leave a Reply