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 New! Icon 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.

9 Comments

  1. 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

    Reply
  2. 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.

    Reply
  3. 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.

    Reply
  4. 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.

    Reply

Have a thought or opinion?