SharePoint – Creating Page Layouts for Custom Content Types

Posted by: Sumit Maitra , on 1/18/2011, in Category SharePoint
Views: 154049
Abstract: In my previous article Custom Content Types in SharePoint, I demonstrated how we can create custom content types in SharePoint. However we left one piece open where we couldn’t see the data that was entered in the list through the default content type. We had to go to List->Edit Properties to edit/update or view the values. In this article we’ll see how we can define custom page layouts for Custom Content Types in SharePoint

In my previous article Custom Content Types in SharePoint, I demonstrated how we can create custom content types in SharePoint. However we left one piece open where we couldn’t see the data that was entered in the list through the default content type. We had to go to List->Edit Properties to edit/update or view the values. In this article we’ll see how we can define custom page layouts for Custom Content Types in SharePoint. We will quickly recap the creation of a new Content Type. This time we’ll use a Publishing Content Type as the parent type and the site will be using a ‘Publishing’ site template.

Creating a Custom Publishing Content Type

This is quick recap of my previous article with one change as detailed below

1. Follow steps 1-4

2. In Step 5 where we’ve to make sure of the following under “Parent Content Type:”

a. “Select Parent content type from:” is set to ‘Publishing Content Type’

b. “Parent Content Type:” is set to ‘Page’

These two settings are important else you won’t be able to use the content type in a custom the page layout (created through SharePoint Designer).

Parent Content Type

Click OK and add the required columns to the content type as defined in Step 6 in my previous article.

You will notice a few extra columns in the default content type this time, because our content type is inheriting from “Page” Content Type. You can keep them because they are optional. Best part about the custom page layout is you can choose to show/hide the fields you want for the document.

Once we are done adding columns for our ‘Functional Specification’ the list of columns should look something like the list below.

Functional Specs

Note: It’s important for the parent site to use a Publishing Site template. Else custom page layouts cannot be created through designer.

Creating Custom Page Layout

To create a custom page layout we’ll use SharePoint Designer. It’s a freely downloadable tool from Microsoft. You can download the 32 bit version or the 64 bit version

Step 1: Start SharePoint Designer.

Step 2: Select ‘Sites’ and click on ‘Open Site’.

Sharepoint Open Site

Step 3: Give the site name and click Open. You’ll be prompted for credentials. Provide credentials of a site collection admin user.

Step 4: Under ‘Site Objects’ in the left navigation pane, select ‘Page Layouts’

Page Layouts

Step 5: Click on ‘New Page Layout’ button in the ‘Page Layouts’ ribbon. You will get a dialog asking you to select the content type. Here we will select the custom content type we created. Provide a filename in the URL Name field and a page title in the Title field. Click OK to continue.

New Page Layout

Step 6: In a few seconds, the skeleton layout page (aspx) will be created and opened in SPD. It’s a standard ASPX page. If you are not too much into web development, just consider it as a well formed xml. All you care about is putting your content in <asp:Content …></asp:Content> tags.

The thing of most interest for us is the Toolbox on the right. Expand the SharePoint Controls pane and you’ll see ‘Page Fields’ and ‘Content Fields’ section. Here you’ll see the Content Type columns we had defined have been all pulled in.

Content Type Columns

Step 7: Drag and Drop all the fields you need on the ASPX page inside the <asp:Content></asp:Content> tags. Unlike me if you are an HTML/CSS guru, here is where you get creative. In the end, the page should have all the content type fields you need and at a very minimum it will be good to include all the mandatory ones. My best effort looks as follows:

ASP Content Tags

Note: Observe when you drop the fields you have GUID only for the FieldName, so you better label them either before or immediately after you’ve dropped the field, else you’ll forget which field you dropped.

Step 8: Save the page (trusty old Ctrl+S) and switch to the ‘Page Layouts’ tab. Here you’ll see the ‘FunctionalSpectLayout.aspx’ has a checkmark against its name.

Page Layout Tab

Step 9: Right click on ‘FunctionalSpecLayout.aspx’ and select ‘Check In’. You will be prompted with a dialog as follows:

Check In

Make sure you select ‘Publish a major version’ because this is our first publish. Click OK.

Step 10: Clicking on OK will give you the following prompt

Content Approval

Click on ‘Yes’ and wait for SPD to start your default browser. If asked for credentials provide credentials for a Site Collection Admin. A page similar to the following will open up.

Sharepoint Designer

Step 10: Pull down the menu for the ‘FunctionalSpecLayout.aspx’ by click on the down arrow. Select ‘Approve/Reject’ from the menu.

Approve Reject

Step 11: It will pop-up a window with the following options. Select Approved, provide comments and hit OK.

Approve Status

Our Custom layout is all but done. Now, let us test it out.

Step 12: Select ‘Site Actions’ > ’Site Settings’. Under ‘Site Administration’ select ‘Site Libraries and Lists’. Click on ‘Customize “Pages”’ link. It will take us to the Page Library settings (shown below) where we’ll add our content type as one of the supported content types.

Page Library Settings

Step 13: Click on ‘Add from existing site content types’ to add our custom content type.

Add Existing Site Content Type

Step 14: In the Above screen select our custom content type ‘Functional Specifications Content Type’ and ‘Add’ it to the ‘Content Types to add’ list. Click OK.

Step 15: Click on ‘Change new button order and default content type’ to disable rest of the templates.

Change New Button Order

Click on the ‘Title, description and navigation’ select ‘Yes’ for visibility in quick launch.

That’s about it. We are all set to test our custom page layout for our very own content type.

Custom Page Layout

Step 16: In the quick launch bar on the left, click on Pages to go the page library. You’ll see a page called default. Ignore this.

Default Page

Click on Documents ribbon and Select ‘New Document’.

Step 17: You’ll be presented with Create new page screen. Fill in the ‘Title’ and ‘Description’. Change ‘URL Name’ if required.

Keep the Page Layout as functional specifications…

Click Create.

Create New Pages screen

Step 19: You will navigate back to the Page library and our first functional spec will be ready for editing

First Functional Spec

Step 20: Click on the Name to see the custom page layout.

Custom PageLayout Preview

Ooohh so pretty!!!! (mimicking my 4 year old)

Now as you see SharePoint is saying the page is checked out and editable. Then why are all the controls read-only? One last step to go.

Step 21: Select the Page ribbon and click on Edit button.

Page Ribbon Edit

OMG where did my pretty page go! Well, we forgot to tell SharePoint not to display labels for the fields in our page layout. But we will ignore that for a moment and wonder at SharePoint’s versatility.

See how the Contacts have picker controls; Dropdowns come in for Choice and Rich text editors (that can pretty much do all the formatting you can do in Word) for Rich HTML fields. All this and “look mama no code”!

No Coed Custom Layout

Disabling Content Type Field Labels in Edit Mode

We saw in Step 21 above how in Edit mode our custom page had duplicate labels. One provided by us in the layout page and another that corresponded to the Field Name of the Content Type. Ideally we would want complete control on our layout so we would like to hide the Column Name that comes automatically. To do this we go back to SharePoint designer and do the following steps.

Step 1: Select FunctionalSpecLayout.aspx from the Page Layouts folder and click on Edit. Say ‘Yes’ for all popups.

Step 2: For each field that we dropped add an attribute DisableInputFieldLabel with value ‘true’.

Disable Input Field Label

Step 3: Once all fields have been updated with the new attribute, Save the file.

Step 4: Click on ‘Page Layouts’ in the left pane. On the right pane, select ‘FunctionalSpecLayout.aspx’.

Step 5: In check-in confirmation dialog, check it in as a minor version.

Step 6: Navigate back to the Page library and edit the page. Confirm that the duplicate labels are now gone.

Conclusion

In this article we saw how a publishing site can be used to create custom content type and then define a custom page layout for the content type. So far we’ve not written a single line of code for all this work.

Next step in our learning process is to use the SharePoint workflow to take our document through an approval process. Even more interesting is development of a SharePoint feature that will convert this editable page into a non-editable document of record.

This article has been editorially reviewed by Suprotim Agarwal.

Absolutely Awesome Book on C# and .NET

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.

We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).

Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.

Click here to Explore the Table of Contents or Download Sample Chapters!

What Others Are Reading!
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+

Author
Sumit is a .NET consultant and has been working on Microsoft Technologies since his college days. He edits, he codes and he manages content when at work. C# is his first love, but he is often seen flirting with Java and Objective C. You can follow him on twitter at @sumitkm or email him at sumitkm [at] gmail


Page copy protected against web site content infringement 	by Copyscape




Feedback - Leave us some adulation, criticism and everything in between!
Comment posted by Benoit on Friday, January 21, 2011 3:14 AM
Blogs like these make me think to upgrade to sp 2010. Very clear instructions you have. Can the above be done in Sharepoint 2003 also?
Comment posted by Sumit on Saturday, January 22, 2011 12:06 AM
@Benoit To be very honest I don't have access to a 2003 SP environment right now. For 2007 the steps are pretty much the same (I actually worked on a live project in 2007). Will try my best to come up with more information for 2003.
Comment posted by Semas on Thursday, February 3, 2011 4:41 AM
Nice step by step article. Are the steps different if you are working with Master Pages? I am having some trouble working this solution on a master page
Comment posted by Sumit on Saturday, February 5, 2011 2:57 AM
@Semas : Can you please elaborate on the problems you are facing? Coming from SP2007 background I found SP 2010 a lot more 'locked down'. The combinations/steps above are the only ones I got working through SP Designer. Also a lot of the previous hacks from 2007 simply throw cryptic exceptions in 2010.
If you can elaborate on the problems or what you are trying to achieve, I can say for sure if it's possible or not.
Comment posted by ff on Friday, March 4, 2011 4:14 AM
Benoit  
Comment posted by Praveen on Saturday, September 24, 2011 11:31 PM
Good one.
I explained a related story here:
http://praveenbattula.blogspot.com/2011/08/set-page-layout-programatically-for.html
Comment posted by Mike on Monday, November 28, 2011 4:47 AM
I have a custom content type inherited by ArticlePage, but when I create a new page with this content type I got a page with content type=ArticlePage, not with mine. What could be the reason ? Of course I can change then the content type to mine in the edit form, but why isn't it created so at once ?
Comment posted by Abdu on Saturday, January 7, 2012 6:56 AM
Good topic.
Just i want to ask about rich text field as it seems doesn't accept the HTML codes.
Comment posted by mathew on Tuesday, January 24, 2012 7:48 AM
If i do all this steps on newly created Document library, instead of default Pages library like in this example, I get Error An unexpected error has occurred. when adding new item to library. I went further and try to create new custom Document library and add to it some default content types, like Article Page, Audio - I get the same error. I thought the step when creating document library and choosing default document template is the problem, but its not. It is library - custom created librarys don't have multi-content type support. Can please someone reproduce this problem, or am I the only one.
Comment posted by Sumit on Wednesday, January 25, 2012 10:15 PM
@mathew : What site template are you using? If I remember correctly you need to use the Publishing Site template when you create the Sharepoint Site.
Comment posted by Pramod Yadav(KNIT) on Saturday, June 2, 2012 7:57 AM
Very helpful article explained every step clearly.......
Comment posted by Regan on Monday, September 3, 2012 9:03 AM
Hey Sumit...Hoping you can help me out...i have been playing around with content types now and creating page layouts etc, i noticed that sharepoint does not allow you to re-use the columns? meaning : I created a custom column for "content info" that needs to be added to my page layout for users to update content. Now I have different sections on the page they need to update info. I had to create a "content column" for each section, instead of just re-using the generic column i already created. am I doing something wrong?
In other words using your example above, I cannot put "open issues" twice on the page and assign different values when editing.
Please advise...Thanks
Comment posted by Daniel Keegan on Thursday, January 17, 2013 11:52 AM
Many thanks for this excellent tut! One of the clearest for SP (any version) I've followed and I learned a lot! Trying to make the client easily browse for an image which will act as this page's background (the page based on the layout) ... may I hit you up if I run into trouble? Thanks again!
Comment posted by sunil on Wednesday, January 23, 2013 11:30 AM
Great post, Thank you
Comment posted by shameem on Friday, May 17, 2013 11:44 AM
Very clear article. thanks
Comment posted by Sandeep Ghodela on Wednesday, April 2, 2014 12:24 AM
Great Article!!! so helpful for me.