Tuesday, June 26, 2007

How to Display the "New" icon against a List Item

To show the standard SharePoint New standard icon SharePoint icon against new list items in a data view web part (or other XSLT web parts), use the following snippet:

<xsl:if test="ddwrt:IfNew(string(@Created))">
    <img src="/_layouts/1033/images/new.gif" alt="New" />
</
xsl:if>

10 comments:

sadalit said...

You are my hero. I was searching for this exact information on the web - found some posts about displaying the document icon, but you were the only one I found to post about the "new" icon. Thank you so much!

Garth said...

Where does this code go?

whats.to.learn.today said...

Insert this code into the XSL of a data view (or data form) web part - this can be done using the code view of the page you are editing in SharePoint Designer.

The XSL of the web part defines what data fields will appear in what rendered HTML - you need to be able to be comfortable with understanding and editing XSL inside of SharePoint Designer to use the code in this post.

Karen said...

Thanks. Works great. Do you know of a way to lengthen the time to display the "New" icon without altering the server configuration...so I can have custom length for each list?

whats.to.learn.today said...
This comment has been removed by the author.
whats.to.learn.today said...

Karen, you could use some additional XSL handling to adjust the @Created date value in the "IfNew" ddwrt command.

For example, you could get today's date using
ddwrt:Today()
and use that to adjust the @Created date, or add some value to the @Created date inside the IfNew() method call using XSL functions. Here are some details of the ddwrt functions.

Frank-Ove Kristiansen said...

Thank you, thank you, thank you! Just what I was looking for.

Sam Ng said...

Can it be added to the content query tool webpart? I have tried to implement it through the itemStyle.xsl but returned with error. Any ideas, please?

Thomas Burke Holland said...

Sam

See this post on adding the !new tag to the CQWP - it's all about the namespace...

http://www.sharepointblogs.com/joed/archive/2008/02/03/display-a-quot-new-quot-indicator-in-the-content-query-web-part.aspx

ollyhodgson said...

This is ace, thanks so much for posting!