简体   繁体   中英

Umbraco publish date in xslt

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

  1. 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
  2. Open the /config/xsltExtensions.config file.
  3. Add the following line to the config:

     <ext assembly=”\\bin\\MyProject” type=”MyProject.Extensions” alias=”MyExtensions”></ext> 
  4. 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”> 
  5. You should be able to use the method now as you would any umbraco.library method eg:

      <xsl:value-of select="MyExtensions:ReleaseDate($myNodeId)" /> 

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM