Monday, March 30, 2009
default.aspx with custom type and layout under Variations
Gaaa!! This was difficult and I am not still sure this was the best way.
Objective was (I guess this is for everybody who uses Sharepoint Publishing portal with Variations enabled. For us, this is to support multiple languages) to have a custom content type and a page layout associated with it for default.aspx, when a subsite is created. And the subsite is propagated by Variations as it is.
That is, you create a subsite in the source label. The default.aspx is of your custom type and layout. And you see the same on all target labels.
First, to have default.aspx of a custom type and layout is achieved, by having a custom Site Definition defined and specifying it upon creation of subsites.
If the objective is just this, you may not need to use a custom Site Definition.
(Although it is a bit backdoor-way) I think we could use as well the Site Template technique. The GUI is provided. Thus, it can be done by a series of clicks.
This was not my option because of the Variations.
Suppose you create a subsite in the source label, based on a Site Template with default.aspx being of your custom type and layout.
The propagation of default.aspx fails because the type does not match.
This is because when Variations creates the subsite (propagation) in a target label, it does so based on the Site Template that you selected when you created the source label. It is either Publishing Site with Workflow or Publishing Site. For both, content type of default.aspx is set to Welcome Page.
How to have our custom Site Template selected there? The answer that I found was to come up with a custom Site Definition.
What I did at the beginning was rather simple. I create my definition having the BLANKINTERNET as basis, and just changed the default.aspx provisioning part so my type and layout are used. This what I have in my onet.xml.
<Configuration ID="2">
...
<Modules>
<Module Name="SubWebWelcome" />
</Modules>
</Configuration>
<Modules>
<Module Name="SubWebWelcome" Url="$Resources:cmscore,List_Pages_UrlName;" Path="">
<File Url="default.aspx" Type="GhostableInLibrary" Level="Draft" >
<Property Name="Title" Value="$Resources:cmscore,IPPT_HomeWelcomePage_Title;" />
<Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/mylayout.aspx, ~SiteCollection/_catalogs/masterpage/mylayout.aspx" />
<Property Name="ContentType" Value="mytype" />
</File>
</Module>
OK. Fine. Looked nice at first. But then I realized that layout is OK but not for the type. The type is Page, not “mytype”.
Actually, up to this far, seems there are many doing the similar. I found blog posts discussing it.
But I found none specifically talking of type. They seemed all happy having their custom layout with default.aspx. Do not tell what happened with the type.
Could be my mistake, oversight somewhere. But I could not figure it out…
After another sometime on the net, I found some people adding custom types to the Pages document library using Feature invoked when a site is created. I gave it a try.
# I later found that the same can be achived using a Feature XML element (http://msdn.microsoft.com/en-us/library/aa543152.aspx), in which case you do not have to do any coding.
Now mytype is added, after the three default types. But still, default.aspx is of type Page, not of my type.
I thought that this may be because the default type of the Pages library is the Page, although it does not make sense because when we create a page thru the UI, it becomes of the type and layout we specify, not of the default type. Actually, when we do so thru the UI, we do not have to add the type first, to begin with.
I looked for a way to change this default (type selected in a document library). But found no such method provided with SPList. It appears that a type is the default just because it comes at the top.
So I decided to see what happens if I deleted the three build-in types, after having added mine.
Bingo!! Now I have the default.aspx created as of my type as well as layout. And since the same definition is used when the site is created in a target label by Variations, there too, the default.aspx is of my type and layout, so the contents are properly propagated.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment