This article was published on my previous blog located at http://blog.avanadeadvisor.com/blogs/patrick_boom in January. I moved it here.
One day, one of our end-users raised the question why the quick launch navigation bar was not visible when adding a new page to an existing site. The user chose the Web Part Page in the Create menu to create a new web part page on the site. After creation, the new page did not show the quick launch bar.
When diving into the issue, indeed, the standard out-of-the-box page templates (8 templates) do not include this bar. To me, this was quite strange, as I could not think of any reason why this would be desired. Nevertheless, when researching the page templates, the default templates override the master page to omit the quick launch navigation bar. And so, the journey to have them added begins.
How are the standard Web Part Page templates called and referenced?
Upon first research I found that the standard 8 templates are hard referenced in a page called spcf.aspx by the create.aspx page. The create.aspx page is the page shown when clicking Create from the Site Settings menu. The Web Part Page option points to a file called spcf.aspx which shows the New Web Page dialog that includes the page layout selection. On this page, 8 page layout options are available by default, dividing the available space in several web part zones in different layouts. The available templates are hardcoded in this page.
There are several approaches one could take in solving this. For example:
1. Locate the standard page templates on disk and modify them
This involves opening the standard page templates in an editor like Visual Studio, look up the overrides off the content placeholder where the quick launch navigation bar resides in the master page and remove them.
2. Keep the existing page templates, but make copies
This involves copying the existing page templates, rename them and then edit them and remove the overrides. Disadvantage would be that we have to change the spcf.aspx page to reference the new templates instead of the standard ones, as these are hard-coded.
3. Keep existing page templates and spcf.aspx, but make copies
Same approach as option 2, but also copying the spcf.aspx page and rename it. This would introduce another disadvantage that we have to change the create.aspx as the spcf.aspx is hard referenced in there.
How to do it without changing any of the standard SharePoint files?
At my current customer, we have several restrictions when applying modifications to the SharePoint landscape. First, none of the out-of-the-box files are allowed to be touched. Secondly, any modifications to the system must be done through a feature packaged in a WSP.
These restrictions rule out all the approaches described above. Secondly, it removes the possibility for creating Web Part Pages without the navigation, for which there could be valid reasons. I have found a way to include them, without touching the OOB files and still honoring the restrictions I had. To be fair though, it is a mere extension of the approach that Paul describes in his blog, so also credits to him. Now, without further due, let us continue to the solution.
There are several steps that need to be taken, which I will describe in detail below. Let us first outline the steps:
1. Create a new Visual Studio empty solution that will host your new feature.
2. Copy the standard page templates and rename them
3. Edit the renamed templates to include the quick launch again
4. Save the preview images for all the standard templates to a location which you can find later
5. Create a new spcf.spx page based on the standard one and modify it to reference the new layouts
6. Create an additional menu option on the Create page to point to your new spcf.aspx page
7. Package all the files into a feature
8. Package the feature in a WSP
Create a new Visual Studio empty project that will host your new feature
Within Visual Studio, create a new empty project to host your new feature. You can use any project type you are accustomed with to create SharePoint features, I just use an empty project. I also use the WSPBuilder extensions to create a WSP, but creating the WSP is out of scope of this blog.
Within your project, create a folder structure to represent your 12 hyve that includes all the locations where we will deploy files, as shown in the attachement PageLayouts Image 1.png.
Copy the standard page templates and rename them
The standard Web Page Page Layouts are located in the 12\Templates\1033\STS\DOCTEMP\SMARTPGS directory, where 1033 stands for English. If you have another language version installed, please replace 1033 with the language identifier installed.
In there, you will find 9 files, of which 8 are aspx pages, called spstd1.aspx through to spstd8.aspx. Make a copy of these files and include them in your project in the same folder. Make sure you rename them to any name you wish, but keep the number suffix, for example, avanade1.aspx.
Edit the renamed templates to include the quick launch again
Open each file in Visual Studio and remove the following lines to add the quick launch again:
asp:Content ContentPlaceHolderId=”PlaceHolderLeftNavBar” runat=”server”>asp:Content>
asp:Content ContentPlaceHolderId=”PlaceHolderNavSpacer” runat=”server”>asp:Content>
Save and close each file.
Save the preview images for all the standard templates
To preserve the preview image for each page template, we copy the preview images for each template to our solution. The preview images are located at 12/TEMPLATES/LAYOUTS/1033/IMAGES and are called SPSTD1.gif to SPSTD8.GIF. Rename the images to the same name used for the templates in previous steps, for example avanade1.gif.
Create a new spcf.aspx page based on the standard one and modify it to reference the new layouts
Paul Papanek included a custspcf.aspx on his blog that also removes the limitation of 8 templates, as the current 2007 implementation of spcf.aspx does. It is therefore recommended to use the one provided by Paul as the basis. You can download it from here http://www.dontpapanic.com/download/custspcf.aspx.txt. You can also copy the existing one from 12/TEMPLATES/LAYOUTS/1033, where again, 1033 is your language identifier.
Include the file in your project and open it in the editor. You may rename the file to any name you want, I just use custspcf.aspx to keep the relationship to spcf.aspx intact. There are a couple of things that you need to change in this file to make it work with your newly created template and images. Do a search on ‘custom1’ and replace all the references to this with the name of your own custom templates, in our example I would replace ‘custom1’ with ‘avanade1’ and so on.
Also find the
SELECT id=”onetidWebPartPageTemplate” name=”WebPartPageTemplate” size=”2″ onchange=”DoTemplateOptionChange()”>
tag, which includes all the possible template options. In the file downloaded from Paul, only two exist. If you take the one from the original spcf.aspx, you will find 8 options. Modify the ‘size’ attribute to reflect the number of copied templates, in our case 8. I added the options exactly as they were in the original file, just renamed the template names, as shown below:
SELECT id=”onetidWebPartPageTemplate” name=”WebPartPageTemplate” size=”8″ onchange=”DoTemplateOptionChange()”>
OPTION value=”avanade1″>Full Page, VerticalOPTION>
OPTION value=”avanade3″>Header, Left Column, BodyOPTION>
OPTION value=”avanade4″>Header, Right Column, BodyOPTION>
OPTION value=”avanade2″ selected=”true”>Header, Footer, 3 ColumnsOPTION>
OPTION value=”avanade5″>Header, Footer, 2 Columns, 4 RowsOPTION>
OPTION value=”avanade6″>Header, Footer, 4 Columns, Top RowOPTION>
OPTION value=”avanade7″>Left Column, Header, Footer, Top Row, 3 ColumnsOPTION>
OPTION value=”avanade8″>Right Column, Header, Footer, Top Row, 3 ColumnsOPTION>
In fact, most of the work is now done. The only thing left is ensure that we can call our new pages from the Create page in the SharePoint UI.
Create an additional menu option on the Create page to point to your new spcf.aspx page
Most menus in SharePoint can be extended with custom actions, like context menus, the Site Actions and so on. This is because these menus also use the FeatureLinks feature that allows additions to this menu. We will use this to add our custom option to the Create page.
Create a feature.xml within our feature folder in our solution, in my case called Avanade.PageLayouts. The contents of the feature.xml is shown below:
<?xml version=”1.0″ encoding=”utf-8″?>
Title=”Avanade – Custom Web Pages Menu Option”
Description=”Enables a custom menu item for creating Web Part Pages with quick Launch navigation.”
<ElementManifest Location=”CustomWebPages.xml” />
The feature refers to an ElementManifest called CustomWebPages.xml which will include the menu option. In my case, I scoped the feature to Farm, enabling the custom templates across all sites in the Farm. You can use WebApplication, Site or Web scope if desired.
The contents of CustomWebPages.xml is shown below.
<xml version=”1.0″ encoding=”utf-8″?>
Title=”Web Part Page with Quick Launch”
Description=”Create a Web Part Page with quick launch navigation”
<UrlAction Url=”_layouts/custspcf.aspx” />
Within this file, we define a custom action with the following attributes:
Id: Identifies your custom action
Title: Is shown in the user interface as the menu option
Description: Is shown on top of the page as description of the menu option
Location: Determines the location (page) to apply the custom action on. In our case, this refers to the Microsoft.SharePoint.Create location, which is the Create.aspx page.
GroupId: Identifies the menu (column) to add the option to, in our case the ‘WebPages’ column.
UrlAction: Identifies the page called when clicking the menu option, in our case, this should point to our newly created custspcf.aspx page, which completes the circle.
That’s it! Only thing left is to package the feature into a WSP to facilitate easy distribution and installation. If you do not use a WSP, you should also include an ElementManifest to deploy the different files to their location. When creating a WSP from this folder structure, WSPBuilder will take care of the deployment of the files for you.
I hope this could be of use to you. Happy coding!