Being a fan of DRY to write maintainable code I'm having some problems getting to terms with SharePoint development. Some information (e.g. GUIDs) is often repeated and spread out over several files, making it hard to know how things relate to each ohter, and I'm always looking for ways to do things programmatically (where I can use e.g. constants and get compile-time consistency checks), rather than via XML files spread out all over the project. Here's an example:
I'm using the Publishing capabilities of SharePoint and want to provide a certain PageLayout associated with a certain Content Type for a certain site. In one place I'm defining the Content Type, MyContentType. In a PageLayouts module I'm provisioning the PageLayout file (MyPageLayout.aspx) using something like:
<File Path="PageLayouts\MyPageLayout.aspx" Url="MyPageLayout.aspx" Type="GhostableInLibrary" > <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" /> <Property Name="PublishingAssociatedContentType" Value=";#MyContentType;#LongGUID;#" /> </File>
And in the onet.xml file I have a ContentTypeBinding element that associates MyContentType with the Pages list on e.g. MySite. Again I have to repeat the ContentType GUID.
Ideally I'd like to just have the onet.xml and have some callback being run when a new site is created based on the MySite template. In the callback I would programmatically ensure the required PageLayouts have been provisioned and made available in the gallery, and at the same time create Content Types as necessary.
Is this, or something like it, possible?