Spicing Up an EPiServer:NewsList with jQuery
I’m no super developer who understands in depth a multitude of programming languages and what you can use them for. My preferred approach is to browse my favourite sites on the web and figure out how I can adapt the things I like to work for me. I usually take a peak at the source code or find tutorials to point me in the right direction. Doing so one day I came across jQuery and have since made use of it both with and without EPiServer.
There are lots of things you could do with jQuery but for this post, I am going to demonstrate two methods for spicing up an EPiServer:NewsList by simply referencing the jQuery library and adding a few short lines of code.
In order to replicate the examples below you will need to set up some properties against your news articles.
- Summary – String < 255
- Main Image – An Image reference which will contain images all of the same size. I achieve this by predefining size options in my web.config. I use images that are 600 x 275. These sizes are referenced in the style sheet so be sure to change them to match your own sizes.
- PageLink – I also use the built in PageLink property.
There are a number of options you could use to create a slideshow effect for your News articles with jQuery. I am making use of InnerFade by Medien Freunde. Alternatively you could use jCarousel which has a nicer effect but I found issues with viewing the output in Edit mode.
First of all add the references to your jQuery libraries. You can either download the main jQuery library or reference Google’s copy. The InnerFade jQuery file comes from the site referenced above.
Pay careful attention to the order you reference your jQuery libraries within your HTML code. I have noticed that if the main library is not referenced first the rest of the code will not work. A bug which caught me out a few times.
I have a User Control called HeadTag.ascx which is used to contain everything within <HTML><HEAD></HEAD></HTML>. My references live there.
Secondly set up your NewsList control. For the slideshow I am simply creating a Unordered List <ul> with an id=”slideshow” which I will later apply CSS Styles and some jQuery too to make it work.
Then some styles for your CSS.
From this I would expect to get an unordered list of images with an link to the page and a summary paragraph. The defacto standard way of presenting news or lists.
To transform this list to a nice single entry, image rotating and fading news gallery you need only apply a few simple lines of code. Put this just before your NewsList control and ensure that the id you reference is the same as you applied to the NewsList HeaderTemplate <ul> and not the actual control id.
So add some news articles and if you’ve done it right, and I’ve written the write instructions (!), then you should have something that looks like this and changes every 5 seconds.