SharePoint !NEW Item Icon
It’s a simple little thing to put into your DVWP, but by adding this little snippet of XSL:
<xsl:if test="ddwrt:IfNew(string(@Created))"> <IMG SRC="/_layouts/1033/images/new.gif" alt="New" /> </xsl:if>
you can automagically get the little icon we’re all so used to seeing if an item has been created within a fixed set of time. The ddwrt:IfNew function simply tests to see if the date you pass it has occurred since the days-to-show-new-icon property value on your server. Don’t forget that you can pass a date in other than Created should you want to test something else. If you are doing this in a DVWP, of course, you can also use an icon which is different than /_layouts/1033/images/new.gif.
By default the days-to-show-new-icon property is set to 2 days, but you can change this property with STSADM:
stsadm.exe -o setproperty -pn days-to-show-new-icon -pv [number_of_days] -url [servername]
If you’d rather not see the icon at all, then set the property to 0.
After setting the property to 7 days the function still returns 2 days when used in ItemStyle.xsl for some reason. SP2010.
d:
That’s surprising. I wrote this post long ago in the 2007 timeframe, but I believe that things work the sme in 2010.
M.
Hi Marc
It would seem not. I am getting completely inconsistent results using it from ItemStyle.xsl.
Results as follows
1. Set days to show to 7.
2. Doc A which is 2 days old shows icon (created post changing setting).
3. Doc B which is 6 days old does not show icon.
4. Set days back to 2 (I day later).
5. Doc A which is now 3 days old shows icon
6. Doc B does not
If I view the docs in the default displays then no problem as the icons are displayed correctly according to the days to show setting.
The new way of testing is by using “@Created_x0020_Date.ifnew=’1′” however this is not available when selecting using the content query or at least that I can tell.
D
The problem appears to be that “ddwrt:IfNew” always uses the default of 2 days in Sharepoint 2010.
So if you change it to something else then it does not work.
d:
I could swear I’ve seen it work properly in a DVWP, but it’s been a while. You could also do the test in your XSL if you need to.
M.
I have a custom template in ItemStyle.xsl which has the following code
No matter what the value is for “days_to_show..” it always uses the 2 day default for determining whether or not to show the icon.
I have not tried it in DVWP but I might give it a go when I get sometime.
In SharePoint 2010, I try to add the code between the Content Query’s XSL tag, but after I save the change in SharePoint Designer, it deletes the code.
Rick:
If you’re not putting the code in a valid location, SharePoint Designer may remove it.
M.
Not sure then where exactly it goes.