Saturday, January 02, 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 © 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.
Sorry, comments are currently disabled due to spam abuse.