Another frequent request I receive is the ability to post a message that the site is under construction or an important announcement needs to be displayed. For the announcements, many of my customers do not want to use the actual SharePoint Announcement list. They just want something that stands out on their home page.
So I usually provide one of two solutions:
- Scrolling Marquee with no styles
- Scrolling Marquee with styles
Scrolling Marquee (No Styles)
Well, what I actually mean by 'no styles' is simple HTML code with no need to create XSL templates. Usually this is the easiest way to go. But for some other assignments with more complex needs, I had to recourse to well, a little bit more complex of a solution.
And for the simple, easy to implement solution, this is what I do:
1. Add a Content Editor Web Part to the page where you would like to display a marquee
2. Edit and modify the Content Editor web part properties, remove the chrome, make any other changes as desired, give the web part a meaningful name (for example, Marquee), and then select [Apply] followed by [OK]
3. Select Click here to add new content at the Content Editor Web Part
4. Locate the HTML icon within the Markup section of the ribbon, select it, and then select Edit HTML Source
5. Type in or copy and paste the code below in the HTML Source web page dialog
<FONT face="Verdana" color=#ff0000 size=2>
<MARQUEE scrollDelay=95 width=500 height=16>
<DIV align=left>Note: Replace this sample text with any message applicable to your particular situation.</DIV></MARQUEE></P></FONT>
6. Select [OK] and save the page (and publish if publishing is turned on for your site)
You can change anything that is highlighted in red above, as well as the sample text in blue to suit your own needs.
Note: If SharePoint modifies the code above after you saved and it doesn't render as desired, create a TXT file containing the code above, upload the file to a document library, and reference the file via the Content Editor Web Part.
Scrolling Marquee (With Styles)
In a handful of situations I had to create something a little bit more complex than the simple HTML marquee above. For those cases, I used the following elements:
- Site Column (Optional)
- Custom List
- Styles (CSS)
- XSL Template
- Customized Content Query Web Part
Step 1 - Site Column (Optional)
Since I don't like doing things more times than absolutely necessary, for most part I end up creating site columns for columns I know I'm going to be using at more than one list or library. For this particular scenario, I created a site column named DisplayYN (Yes/No checkbox or Choice (Yes/No) column). For this example, we are going to say the DisplayYN column is Boolean (Yes/No checkbox).
Step 2 - Create Alerts Custom List
The next step was to create a custom list to manage the Alerts. The list would contain only a couple of columns:
- Title (the text for the alert)
- DisplayYN site column
You may be asking yourself why the custom list and why the DisplayYN flag. In many projects I have to work on there's a business approval process behind the scenes where usually the person who creates the text and items on the list is not necessarily the one who gives the green light to display the alerts on the sites. So these people go through review processes until everybody is happy and then the person responsible for the site or alerts edits the item and selects DisplayYN to 'Yes.'
Step 3 - Create The Necessary Styles (CSS)
I create a custom style definition in my CSS file (the copy I created from the corev4.css file). If you have been following my posts, then you know how I advocate towards making copies of Microsoft's files and leaving their original files alone. So back to that point, the following is an example class I may create:
font-family: Verdana, Helvetica, Arial, sans-serif;
padding: 3px 3px 3px 3px;
border: 1px gray solid;
Don't forget to check in and publish (if needed) your CSS file for the changes to become visible to those users who have been granted the lowest access levels to the site, as well as registering and referencing your external CSS file on your custom master page, as needed.
Step 4 - Create The Necessary Item Style Templates
In your XSL Style Sheet (the one that I hope you copied from Microsoft's original) I create a template, as follows,
<xsl:template name="Alert" match="Row[@'Alert']" mode="itemstyle">
<div id="alert" class="myAlert">
<marquee scrollamount="2" scrolldelay="1"><xsl:value-of select="@Title"/></marquee>
Some designers also like to include an entry on their Content Query Main to declare the above template. Not everybody follows this rule. Depending on the styles, SharePoint will still render the items on the page, whether you modify the Content Query Main file or not.
Step 5 - Create The Custom Content Query Web Part (CQWP)
I add a CQWP to the home page or page where the alert should display at. I then modify the CQWP to use the custom list as source and I set the filter on DisplayYN equals Yes. That way only those items on the custom alerts list that have been selected to be displayed will display.
For most part, my customers never select more than one item at a time. But they usually want to know which other alerts they had published before. That's when this second solution turns out to be better than the simple HTML shared further above.
Then I export the CQWP to my computer and I open it using a tool like Notepad. I then make the following changes:
<property name="ItemXslLink" >/sites/SiteName/Style Library/XSL Style Sheets/CUSTOMItemStyle.xsl</property>
<property name="MainXslLink" >/sites/SiteName/Style Library/XSL Style Sheets/CUSTOMContentQueryMain.xsl</property>
<property name="Xsl" ><xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cmswrt="http://schemas.microsoft.com/WebPart/v3/Publishing/runtime" exclude-result-prefixes="xsl cmswrt x" > <xsl:import href="/Style Library/XSL Style Sheets/Header.xsl" /> <xsl:import href="/Style Library/XSL Style Sheets/CUSTOMItemStyle.xsl" /> <xsl:import href="/Style Library/XSL Style Sheets/CUSTOMContentQueryMain.xsl" /> </xsl:stylesheet></property>
I save and then I import the updated CQWP to the page. The last thing is to select my style within the drop-down Presentation list within the CQWP tool pane. And finally, I delete the original CQWP from the page once I make sure the customized one is working as expected.