All about the Strategy, Design, Customisation, Deployment and Development of SharePoint and its related Technologies

  Administration   All Me!! Baby!!   Business   CKS   CQWP   Development   Duffer Moments   Email   Errors   Family   Fixes   General   Groove   How To   How To Code   InfoPath   IRM   Longhorn   Lotus Notes   Migration   Mobility   Office System 2007   Personal Projects   Records Management   Search Server   Security   SharePoint   Silverlight   SQL   Tech Ed 2008   Testing   Vista   VSTO   WSS   XSL

[26/08/2007] MOSS2007 – Page Layouts and CSS
 
Categories: Development, Office System 2007, SharePoint
 

While working on a current project, we faced a little issue of deciding how to create "News" easily. Within MOSS2007 you have the ability to create news in different ways. The old fashioned way was to use various lists and use the built in web parts to display them or use the data view web part (DVWP). This way worked well until now, when in MOSS2007 you have the publishing features that allow us to create "News Pages" based on different layouts and then consume them using the Content Query Web Part (CQWP). We decided that the way forward to start with was to use the new inbuilt publishing features for the news. This worked great but almost seemed like an overhead. Having to create a new page for each news article seemed a little too much. Also the users were not 100% happy with the way that they had to choose "Create Page", and then define the layout before they even got to add the content. So we decided to change it and go back to using a list. This has a few advantages to the previous design but the main reason was because the users wanted a nice structured form to fill in, no layouts, and no extra choices. In reality they wanted it nice and simple. So the list was created so when you added a new item it looked as below: (*News taken from BBC website*)

Notice how neat the form is that it is very simple to complete the form. However the flip side to this was that when you viewed the new item it looked as below:

Notice once again the titles of the columns showing. This is great but not really with keeping of the overall design and layout. I decided to fix this by using a Data View Web Part to show the news instead of a Content Query Web Part and created a custom "DispForm.aspx" that took the ID of the list item and rendered it without all the extra columns. This worked well, however it did seem a little "Clunky" and didn't seem to be the correct way of doing it. So back the drawing board again, this time I went back to using page layouts. So this time when creating news you have to select the "Create Page" link from "Site Actions" and then select the page layout.

Once you have completed the details for the initial page creation, you are left with a page that looks as below:

Notice how it doesn't look very pretty and the layout isn't what you would really expect. So after completing the news in this layout we end up with the same news as before looking as below:

The page renders and this time the columns don't show but the layout isn't the best. To fix this issue was very simple we created custom page layouts. This is well documented and the best approach to take. However we did come across an issue that meant we potentially had to go back to the list option. The issue here is that the "Page Layout" once it had been designed looked just like we wanted to when it rendered it to the users, not how the contributors wanted to look like while filling it in. So our next challenge was to somehow create a page layout that looked different depending on whether you were editing it or viewing it. My initial idea was to write something in code, but then I thought maybe we could use some JavaScript to manipulate the page on loading. After a quick chat to a fellow MVP Ben Robb I decided to investigate using CSS to hide or show the relevant panels that I needed. The steps I took are below:

  1. Create Custom Page Layout
  2. Create "<DIV>" for viewing section
  3. Add relevant fields from page columns and content type to viewing section

NOTE: I had not even realised that you can add the "Page Content" control or in fact any of the controls to the page as many times as you want as long as the associated "Fieldname" is correct and the actual ID is changed

  1. Create "<DIV>" for editing section
  2. Add relevant fields from page columns and content type to editing section – generally more fields in this section
  3. Add some CSS tags into the "Editing Panel" to hide the "Viewing" DIV

If I open up the custom page layout within SharePoint Designer you can see that there are two defined area. The top area is for viewing and the bottom area is the editing section. I have changed the background and added a red boxed outline around the editing panel to highlight it.

Within the editing panel I have also added the following:

This code simply uses CSS to hide the top area for viewing, also as it is only ran when the "Edit Panel" loads it only ever hides the "View Panel" when editing the page. When you now edit a news item based on the custom page layout it should render as below (notice how only the edit panel is visible):

Once the page has been re-saved and then published it should then render just the viewing panel as the "Edit Panel" is hidden by default anyway.

As you can see is only a quick demonstration what you can do using a little single CSS Style. For the live solution there is a lot more involved in hiding certain areas as the layouts page also contains web parts that cannot be edited. The key to making this approach work is simply making sure that your mark-up is correct and that it is really valid XHTML. Anyway this helped me so maybe it might be useful to you. J

NOTE: The news has been taken from the BBC News website just for ease and convenience.

 
7 Comments
 

Comments

Monday, 27 Aug 2007 07:28 by Martin
Very nice.

Just one question: At the moment we have a news application that only shows unread news to the user in the initial view. (Just like the "unread mail" search folder from outlook.)

Does MOSS 2007 support something like this (a per user and per item read/ unread flag)?

By the way: If someone has to pitch MOSS against SAP Enterprise Portal, I have a written statement from SAP (in German) that reads: "Don't log on the user immediately and don't use personalized views on the home page of users."

Unbelievable.

Wednesday, 29 Aug 2007 03:24 by Andy
Very interesting. However, if you're just using CSS to hide bits of the page, does that not mean you're sending the HTML for both parts each time? How much of a bandwidth overhead is that?

Sunday, 9 Sep 2007 08:34 by Liam Cleary
Hey Martin,
   There is no "Marks as Read" or "Mark as Unread" within MOSS2007 when it comes to news items. I suppose you could build something like this but it would complicated. Could be quite useful to create though! :-)

Like the comment about SAP!! Very cool. :-)

Sunday, 9 Sep 2007 08:36 by Liam Cleary
Hi Andy,
   Yes I was concerned about this, but after some testing the only time it can cause an issue is if the page is constanly getting "Edits" made. The amount of data being pushed over and above the normal page doesn't cause too much of an overhead. I know you are loading twice the amount at time of "Edit" but so far so good. Seems to work like a treat.

Tuesday, 25 Sep 2007 09:01 by Joost Schermers
Hi,

I don't quite understand this post. You can just use the edit mode panel to hide content from view. Why also use CSS.
It looks to me you are using the default news option for publishing news. Even though you wrote this "We decided that the way forward to start with was to use the new inbuilt publishing features for the news. This worked great but almost seemed like an overhead. Having to create a new page for each news article seemed a little too much."

The conclusion seems to me you are still using the create page option...so there still is overhead for the customer. Or am i wrong here?? I'm struggling with this myself! I thought perhaps you option using lists could solve this...but the view is rather ugly.

Tuesday, 25 Sep 2007 12:22 by Liam Cleary
Hi,
The logic behind using the CSS was to hide the controls when in edit mode. When you add a content type field or page control to the page you can either add it to the main body or stick it in the edit panel which will hide it when it renders in live. However what was needed was when the news was filled in the page actually shows the edit panel and all the live rendering controls. Using the CSS was a way to add the "PublishingPageContent" control to both the Edit panel and the main body but only show it in the editing panel when in edit and vice versa in live mode. If you look at your published page within edit mode you will see that you get the live controls at the top and then the edit panel at the bottom. The requirement was to *ONLY* show the edit panel when in edit mode, not the other controls that appear at the top. Hope this makes sense.

Friday, 2 Nov 2007 06:09 by Kiran
Hi, I created a publishing page following the instructions from http://office.microsoft.com/en-us/sharepointdesigner/HA101741281033.aspx. While doing so, I added 2 Rollup Image controls(Page Fields), 2 RichTextBoxes(custom) with different IDs to the page layout and published. Now to the publishing page, I applied the above page layout. I added 2 different Images to the Rollup Image controls and 2 different contents to the Richtextboxes. When I saved and checked in, both the Image controls contain the same image and both the RichTextBoxes contain the same text... Any clue about this? and how to fix it.. Thank you Tom

Name:

URL:

Email:

Comments: