Last week I had to teach the concept of publishing features to SharePoint newbies, and they struggled with the notions of Content Types, Page Layouts and so on. I decided to compile these concepts in a 2 blog posts.
1.Create a new Site collection (in my case the url will be http://litare/sites/dev) and choose the team site template for the root site.
2.Activate the SharePoint Server Publishing Infrastructure feature at the site collection level.
3.Go to your root site-Site Content Menu and notice the different lists created by this publishing feature.
- Content and Structured Reports
- Reusable Content
- Site Collection Documents
- Site Collection Images
- Workflow Tasks
4.Activate the SharePoint Publishing features at the site level.
5.Go to your root site-Site Content Menu and notice the different lists created by this publishing feature.
All page of a publishing site are supposed to be grabbed from the Pages library. This will be the case if you create a web site based on a publishing template like the Publishing Portal or the Enterprise Wiki templates for instance.
6. Go to your Pages library and create a new Page based on the Welcome content type :
After that, set your page name and url respectively Home and Home.aspx; select the Welcome Blank Web Part page Page Layout :
Indeed several page layouts can be created from the same Content type. Click the generated page, edit the page and add some kind of Welcome text on it:
7. Specify your web site welcome page : go to Site Settings : in the Look & Feel group, select Welcome Page.
and browse to select your newly created Home page.
8.Create the Page Layout Content Type : each field of a Page layout is mapped to the site column of a Content type derived from the Page content type;
we can easily create the content type by using the browser and we can create the page layout by using SharePoint Designer (this post) or the Design Manager (next post) but don’t forget that we usually have several environments : Development, Integration, Test, production : therefore we must be able to move our artefacts (Content Types and Page Layouts) to the differenrs environments :
in a first stept developers will create the artefacts on their dev workstations, then they will deploy them to the integration environment, then to Test then to Production. In many situations they will have to move the production content db to the Test environnement, they will have to update the artefacts in dev, Test, production and so on… and this must be automated –> we need to create feature to do it.
So basically if you have to deal with releases and branching, you will have to automate your deployments –> SharePoint features are your friends; even in the Cloud (office 365) : keep in mind that any CAML code can be deployed to the cloud, which is CAML friendly (contrary to .Net code unless you write provider hosted apps or Auto hosted apps, but this is beyound the scope of this post).
let’s start Visual Studio 2013 (“I’m using the Preview version for this post, but can also use Visual Studio 2012 : in this case make sure the Office & SharePoint developers tools are installed; it looks like they are included in VS2013 preview by default);
Create a new SharePoint Project (could be farm or Sandbox) : I’ve called the solution DemoPageLayout
I always store all SharePoint artefacts in dedicated folders, so let’s create 3 folders as illustrated below:
Our Content Type will have 3 site columns :
- Job type
- Job description
- Job prerequisites
Job Type is an out of the box site column, so we should only create the 2 other site columns :
Create the Job description site column :
Proceed to the following modifications in Elements.xml :
Create the Job prerequistes site column and proceed to the following modifications :
In the Content Types folder, let’s create our JobPosting content type:
When requested, derive it from the Page content type.
In the content type designer, add the following Site Columns:
And set Job Title as Required.
Go to the elements.xml file and set the (Content type) Group to ShareQL
Now Deploy your SharePoint Solution to the Server.
Double check to make sure your content type is deployed and contains all your 3 site columns
Let’s focus to to the Page Layout: basically we have 2 options for creating the Page Layout :
- SharePoint Designer 2013 (this post)
- Design Manager (new in SharePoint 2013 – see next post)
In this post, I will create the Page Layout with SharePoint Designer; in the next post, we will use the new Design Manager and will compare the 2 options.
Open your web site with SharePoint Designer 2013, go to the Page Layouts Panel and click on New Page Layout:
Fill in the following form : (we will name the file JobPostingSPD.aspx->specify JobPostingSPD in the url)
Display the ToolBox Pane by clicking on the View Ribbon-Task Panes menu : the Toolbox Pane will show up on the right side of the window; in the SharePoint Controls group, you will find your Content Type fields :
Open your aspx page and type the following lines in the PlaceHolderMain (we won’t use html tables):
The good practice when usying css styles is to share them in a separate file.
Now to each </span>, drag and drop the correspond field from the Toobox :
Also, as a developer it is worth noting that the layout page is derived from the PublishingLayoutPage class :
Go to the Pages library, add the JobPosting content type.
Go to the Pages library and add a new document : the JobPosting content type should be visible
Provide your Page Title and Page url : (notice the Page Layout Category : by default the content type is under ( ) ; indeed several page layouts could use the same Content Type).
Save the page and edit the page :
Save the Page :
Since we are curious, let’s download the new content page we just created :
Open the downloaded page with your favorite content editor and replace “SharePoint developer” with “SharePoint consultant”; save the file and upload it to the Pages library (replace the existing content).
Also take a look at the @Page directive : you will notice that this page is derived from the class TemplateRedirectionPage that transfers execution to the page layout.
You will also notice a reference to ~masterurl/custom.master which is an indication that the page layout uses the web site custom master page.
Now when you run the uploaded page, you will see the new value:
Ok, now that it looks like our Page Layout works, we need to be able to deploy it from our SharePoint solution package.
First remove all the pages you just created for your tests and remove the associated Job Posting content type from the list.
In our Visual Studio 2013 project, go to the PageLayouts folder and add a new module SharePoint Project Item.
Download the JobPostingSPD.aspx page we just created and add it to the Module folder. Make sure the <module> elements looks like this:
Deploy your package, add the content type to your Pages list, and create a new content Page based on the job posting Page Layout.
To make sure the new version of the Page Layout is updated, modify it a little bit by setting the labels in red as illustrated below :
Redeploy the package.
Click on an existing published page, you should see the red labels.
In the real world, the code should improved in order to automatically attach the content type to the Pages lists, and also to make sure that any modification to your content type will spread to the cached content type no this pages list. This is beyond the goal of this post.
In the next post we will illustrate how using Design Manager 2013 is much easier than we we just did.