Various Umbraco references point out that Umbraco only stores the node createDate and updateDate in umbraco.config (when you want to code up xslt transformations of Umbraco content).
But I need to be able to display the publish date in xslt transformations.
Now after working out that in the Umbraco database cmsContentVersion.VersionDate is the node publish date and cmdDocument.updateDate is the last updated date I can create a trigger that changes the updateDate to match the publish date whenever whenever the publish date changes and use the following xsl:
<xsl:value-of select="umbraco.library:FormatDateTime(@updateDate, 'd MMM yyyy hh:mm')"/>
But ideally I don't want to change the core Umbraco table definitions.
I found this reference which suggested extending the node document to expose the release date in C#, using:
public static string ReleaseDate(int nodeId) {
Document d = new Document(nodeId);
return d.ReleaseDate.ToString();
}
... but how do I translate that C# in xslt? Rewriting the xslt as ascx ma开发者_如何学Gocros is not an option.
You could use an XSLT extension. See this tutorial (http://www.nibble.be/?p=60), but I've adapted it here.
- Place that .NET code in a class called Extensions in an assembly that is built and copied to the bin folder of your umbraco install. For example we'll put it in MyProject.dll
- Open the /config/xsltExtensions.config file.
Add the following line to the config:
<ext assembly=”\bin\MyProject” type=”MyProject.Extensions” alias=”MyExtensions”></ext>
In your xslt, add a reference to the extension and exclude the prefix:
<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” xmlns:msxml=”urn:schemas-microsoft-com:xslt” xmlns:umbraco.library=”urn:umbraco.library” xmlns:BlogLibrary=”urn:MyExtensions” exclude-result-prefixes=”msxml umbraco.library MyExtensions”>
You should be able to use the method now as you would any umbraco.library method e.g:
<xsl:value-of select="MyExtensions:ReleaseDate($myNodeId)" />
Hope this helps.
精彩评论