Una Feature per deployare un Page Layout di SharePoint
Questo esempio mostra come deployare un nuovo Page Layout per SharePoint 2007 (MOSS) con il relativo content type e colonne di sito (site columns).
Per far questo servono tre file:
File: feature.xml
File: elements.xml
Da qui si può vedere come:
File: SgartPageLayout.aspx
Per installare la feature copiare i 3 file in una cartella SgartPageLayout sotto ...\12\TEMPLATE\FEATURES , ed eseguire i seguente comandi per rimuoverla/instllarla:
Per far questo servono tre file:
- feature.xml che contiene la descrizione della feature, il guid ed il riferimento al file elements.xml e SgartPageLayout.aspx
- elements.xml contiene la definizione delle colonne di sito, del content type (che deriva da Page) usato dal page layout e la posizione in cui verrà deployato il page layout (SgartPageLayout.aspx)
- SgartPageLayout.aspx il page layout che contiene un campo di tipo link (visibile solo in edit), un campo immagine ed un campo html, oltre a una WebPart zone
File: feature.xml
XML
<Feature Id="4B191320-D981-42e2-A67D-AC7E8BAA5D4C"
Title="Sgart Page Layout"
Description="Sample feature to deploy site column, content type and page layout"
Version="1.0.0.0"
Scope="Site"
Hidden="FALSE"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="elements.xml"/>
<ElementFile Location="SgartPageLayout.aspx"/>
</ElementManifests>
</Feature>
File: elements.xml
XML
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- add site columns (fields) -->
<Field ID="{40DD126E-B4D4-4ab0-AD6E-F780E53E46CA}"
Name="SgartPublishingPageText"
StaticName="SgartPublishingPageText"
Group="Sgart $Resources:cmscore,group_pagelayoutcolumns;"
DisplayName="Testo libero"
Type="HTML"
Required="FALSE"
Sealed="TRUE"
RichText="TRUE"
RichTextMode="FullHtml"
SourceID="http://schemas.microsoft.com/sharepoint/v3"/>
<Field ID="{2D9F82E5-5230-451c-BA64-66F27C87ACFA}"
Name="SgartPublishingPageLnk"
StaticName="SgartPublishingPageLnk"
Group="Sgart $Resources:cmscore,group_pagelayoutcolumns;"
DisplayName="Link"
Type="Link"
Required="FALSE"
SourceID="http://schemas.microsoft.com/sharepoint/v3"/>
<!-- add site content type for page layout -->
<!-- 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39 conten type "Page" -->
<ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900580FEFE87BA243ED974E43E7A095ECAE"
Name="Sgart Page CT"
Description="Sample content type"
Group="Sgart Page Layout Content Types" Sealed="FALSE" Version="0">
<FieldRefs>
<FieldRef ID="{40DD126E-B4D4-4ab0-AD6E-F780E53E46CA}"
Name="SgartPublishingPageText"
DisplayName="Free Text" />
<FieldRef ID="{2D9F82E5-5230-451c-BA64-66F27C87ACFA}"
Name="SgartPublishingPageLnk"
DisplayName="My Link"
Required="TRUE" />
</FieldRefs>
<DocumentTemplate TargetName="/_layouts/CreatePage.aspx" />
</ContentType>
<!-- deploy page layout (PublishingAssociatedContentType = Sgart Page CT) -->
<Module Name="SgartPageLayouts" Url="_catalogs/masterpage" Path="" RootWebOnly="TRUE">
<File Url="SgartPageLayout.aspx" Type="GhostableInLibrary" >
<Property Name="Title" Value="Sgart Page Layout" />
<Property Name="MasterPageDescription" Value="Sgart page layout example" />
<Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
<Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/SgartPageWelcomeLinks.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/SgartPage.png" />
<Property Name="PublishingAssociatedContentType" Value=";#Sgart Page CT;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900580FEFE87BA243ED974E43E7A095ECAE;#" />
</File>
</Module>
</Elements>
- deployare delle colonne di sito (tag Field)
- deployare un content type (tag ContentType), come referenziare delle colonne di sito e come derivare da un content type esistente (aggiungendo all'id 00 e un nuovo guid)
- infine si vede come deployare un file (tag Module e File). In particolare per deployare un Page Layout vanno indicate altre informazioni quali: il content type che identifica il file come un page layout (ContentType) e il content type associato alla pagina (PublishingAssociatedContentType) nella forma ;#nome content type;#id content type;#
File: SgartPageLayout.aspx
HTML
<%@ Page Language="C#"
Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage, Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls"
Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation"
Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:content contentplaceholderid="PlaceHolderAdditionalPageHead" runat="server">
<style type="text/css">
.ms-pagetitleareaframe table, .ms-titleareaframe
{
background: none;
height: 10px;
overflow:hidden;
}
.ms-pagetitle, .ms-titlearea
{
display:none;
}
</style>
<PublishingWebControls:editmodepanel runat="server" id="editmodestyles">
<!-- Styles for edit mode only-->
<SharePointWebControls:CssRegistration ID="CssRegistration1" name="<% $SPUrl:~sitecollection/Style Library/~language/Core Styles/zz2_editMode.css %>" runat="server"/>
</PublishingWebControls:editmodepanel>
</asp:content>
<asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
</asp:Content>
<asp:content contentplaceholderid="PlaceHolderPageTitleInTitleArea" runat="server">
<SharePointWebControls:TextField runat="server" id="TitleField" FieldName="Title"/>
</asp:content>
<asp:content contentplaceholderid="PlaceHolderMain" runat="server">
<SharePointWebControls:CssRegistration ID="CssRegistration2" runat="server"
name="<% $SPUrl:~sitecollection/Style Library/~language/Core Styles/pageLayouts.css %>"/>
<div class="ms-pagebreadcrumb removeMargins">
<asp:SiteMapPath ID="siteMapPath" Runat="server"
SiteMapProvider="CurrentNavSiteMapProviderNoEncode" RenderCurrentNodeAsLink="false"
SkipLinkText="" NodeStyle-CssClass="ms-sitemapdirectional"/>
</div>
<PublishingWebControls:editmodepanel runat="server" id="editmodepanel1">
<!-- Add field controls here to bind custom metadata viewable and editable in edit mode only.-->
<div style="border:solid 1px gray; background-color: #FFFFCC;padding: 5px;">
<strong>Visible only in edit mode</strong>
<!-- new field -->
<PublishingWebControls:RichLinkField id="PageSgartLnk" FieldName="SgartPublishingPageLnk" runat="server" />
</div>
</PublishingWebControls:editmodepanel>
<table width="100%">
<tr>
<td width="50%">
<!-- exitent filed in Content type page -->
<PublishingWebControls:RichImageField id="PageImage" FieldName="PublishingPageImage" runat="server"/>
</td>
<td width="50%">
<!-- new field -->
<PublishingWebControls:RichHtmlField id="PageSgartText" FieldName="SgartPublishingPageText" runat="server"/>
</td>
</tr>
<tr>
<td width="100%" valign="top" colspan="2">
<WebPartPages:WebPartZone ID="TopColumnZone" runat="server"
AllowPersonalization="true" FrameType="TitleBarOnly"
Title="<%$Resources:cms,WebPartZoneTitle_Top%>"
Orientation="Vertical">
<ZoneTemplate></ZoneTemplate>
</WebPartPages:WebPartZone>
</td>
</tr>
</table>
</asp:content>
Per installare la feature copiare i 3 file in una cartella SgartPageLayout sotto ...\12\TEMPLATE\FEATURES , ed eseguire i seguente comandi per rimuoverla/instllarla:
DOS / Batch file
stsadm -o uninstallfeature -name SgartPageLayout
stsadm -o installfeature -name SgartPageLayout