I'm defining a pagelayout in sharepoint. I've defined several zones (webpartzones) surrounded with some DIV tags for controlled positioning.

In those zones i want to be able to put code (custom webpart), images or full formated HTML.

Is there already ImageWebPart - where i can select one image in my libraries to display? Is there alread HtmlWebPart - where i can fill full html to be placed in that zone?



Have you checked out the OOTB webparts that you can add to pages by just editing them?

You have the Content Editor webpart (for HTML) and the Image Viewer webpart for images.

By adding these webpart to a page, and while in edit mode, click on the arrow in the webpart header and then click "Export" you will get a file containing XML.

You can use this XML to provision your Webparts on the page layout in the Module in Visual Studio.

In the File element for your Page layout, you can add a AllUsersWebPart element and in their paste the XML markup from the exported files.

For more about that see this question and answer: How to add web part in page layout?.

|improve this answer|||||

Using Rich HTML Field Controls

In case of HTML content & image in page, Rich HTML Field Controls could be used instead of web parts. Below is demonstrated how Rich HTML Field Controls are declared for SharePoint 2013 Body only page layout (/_catalogs/masterpage/PageFromDocLayout.aspx)

<%@ Page language="C#"   Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<!-- Remaining code is omitted for clarity -->
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
    <div class="article article-body">
        <PublishingWebControls:EditModePanel runat="server" CssClass="edit-mode-panel title-edit">
            <SharePointWebControls:TextField runat="server" FieldName="Title"/>
        <div class="article-content">
            <PublishingWebControls:RichHtmlField FieldName="PublishingPageContent" HasInitialFocus="True" MinimumEditHeight="400px" runat="server"/>
        <PublishingWebControls:EditModePanel runat="server" CssClass="edit-mode-panel roll-up">
            <PublishingWebControls:RichImageField FieldName="PublishingRollupImage" AllowHyperLinks="false" runat="server" />
            <asp:Label text="<%$Resources:cms,Article_rollup_image_text15%>" CssClass="ms-textSmall" runat="server" />

Page in Edit mode

enter image description here


Using Rich HTML Field Controls

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.