Percipient Studios logo

The never-expiring copyright date

02 January 2010
Filed under: xslt - by Douglas Robar

It's January 2... do you know if your site's copyright notice is up-to-date?

With a quick bit of inline XSLT in your umbraco template you need never worry about it again!

Here's how to do it:

<div id="footer">
    COPYRIGHT &copy; 2009 - 
    <umbraco:Item field="pageName" runat="server" xslt="Exslt.ExsltDatesAndTimes:year()" />, 
    PERCIPIENT STUDIOS. ALL RIGHTS RESERVED.
</div>

There are three points you'll want to keep in mind:

  • You must not omit the field="" parameter.
  • You must select a field="" that actually exists.
    This is why I used the "pageName" field.
  • You can select any field="" you want.
    Remember that the xslt="" command will process the field="" parameter passed in before displaying the output; and in our example the xslt ignores the field being passed in.

Alternatives

Or, if you have some objection to the Exslt extension and want to use only the umbraco library, you can achieve the same result with:

    <umbraco:Item field="pageName" runat="server" xslt="umbraco.library:FormatDateTime(umbraco.library:CurrentDate(), 'yyyy')" />,

Or, if you really want to use a full macro, it would look like this:

<xsl:template match="/">
    <xsl:value-of select="Exslt.ExsltDatesAndTimes:year()" />
</xsl:template>

[EDIT] Or, as Casey points out in the comments... if you have a deep love for all things .NET (or aren't a fan of XSLT) you could put this in your template instead of the umbraco:Item:

    <%= DateTime.Now.Year %>

Conclusion

You can now sleep through New Year's day comfortably, thanks to umbraco and XSLT.

Happy New Year!
doug.

3 comments for “The never-expiring copyright date”

  1. Gravatar of Casey Neehouse
    Casey Neehouse says:
    What about simple .NET code.. Put this in your template.

    <%= DateTime.Now.Year %>
  2. Gravatar of Bayshield
    Bayshield says:
    Nice idea! I would probably lean towards the .net version but good to see how simple it is to format dates in XSLT.
  3. Gravatar of Chad Rosenthal
    Chad Rosenthal says:
    I used a similar XSLT approach, but through the item in a Macro, so that I could add it to a starter package that I created.
 
powered by <XSLTsearch>

Categories

Follow Us

RSS Feed
Follow us on Twitter
Follow us on Flickr