Another element you can place in content place holders in a page layout are field controls. Field controls are determined by the site columns which are established through the content types. For instance, if you use an article page layout, you will only see the field controls that are available to the article page layout content type. For now, we will walkthrough how to add field controls to the code of page layouts through Designer. Later, we will dive into how to add a custom field control by using a custom content type. For sanity sake, just know that field controls are derived from the site columns in content types.
Begin by navigating to the page layout gallery and making a new page layout. Call it whatever you like but make sure that you set the “Content Type Group” to “Page Layout Content Types” and then set the “Content Type Name” to “Article Page”. By setting the page layout to be based on this content type, you are exposing all the site columns that are available in that content type to the page layout for use.
After you have your new page layout created, open the page in Designer. A quick way to do this is to find the name of the newly created page layout in the gallery, clicking the dropdown arrow, and choosing “Edit in Microsoft SharePoint Designer”.
Click “OK” if a warning box appears, and then click “Yes” if you’re asked to edit in advanced mode. If you can’t access Designer through the browser, open Designer manually, click the “Page Layouts” folder in the navigation, click the title of the newly created page layout, and then click “Edit File”. Again, click “Yes” if asked to open it in advanced mode.
Once you have the page open for editing, add the content field that you set earlier by first clicking somewhere in the content area with the place holder id of “PlaceHolderMain” and hit enter to place a line break. In the “Insert” tab in the ribbon is a dropdown called “SharePoint”. Clicking this and then clicking the link at the bottom that says “Show Toolbox” will open up the toolbox on the right side of the screen. Scroll to the bottom of the toolbox and you will see a “SharePoint Controls” section with a subsection called “Content Fields”.
Find the field control called “Page Image”, click and drag it directly to the line break you just placed. When you do so, a line of code is automatically generated that looks like this:
Inside this <SharePointWebControls> tag is something called a “FieldName”. This is a unique identifier which is called a GUID. Since GUID’s are unique, yours will not match the one in the sample above. This number is what identifies that image field in the page layout.
After you’ve placed the “Page Image” content field, drag the “Image Caption” field from the tool box and drop it immediately after the line of code that was generated for the page image. This will place another web control called a RichHtmlField and it will have a different GUID than the previous one.
Save your file and return to your browser. Create a new page using this page layout by going to “Site Actions” ⇒ “View all Site Content” ⇒ “Create” ⇒ click the “Page” category on the left and select “Publishing Page” on the right and click “Create”. Doing so will open up a page creation settings box where you will type a title, description, URL, and also select the page layout that it will use. Select the page layout you created earlier and click “Create”.
Once your page is created, you will see the two fields you just placed in the page layout appear. From here, you can place your pictures, add your captions, and click “Save and Close”.
Now every time you use this page layout when creating a new page, it will have an area for a picture and an area for a picture caption. So while my page layout is called Zebra.aspx, I could use it on any new page and put any type of image in it and it will keep the same controls on the page. If you don’t use a control and it stays blank, after you save and close the file, the area will not appear. It still exists if you edit the page but you won’t see it unless it holds data.