简体   繁体   English

Umbraco在xslt中发布日期

[英]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). 各种Umbraco引用指出,Umbraco仅将节点createDate和updateDate存储在umbraco.config中(当您要编码Umbraco内容的xslt转换时)。

But I need to be able to display the publish date in xslt transformations. 但是我需要能够在xslt转换中显示发布日期。

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: 现在,在确定了Umbraco数据库中的日期之后,将cmsContentVersion.VersionDate作为节点的发布日期,将cmdDocument.updateDate作为最后的更新日期,我可以创建一个触发器,该触发器可以在每当发布日期更改时更改updateDate以匹配发布日期,并使用以下命令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. 但理想情况下,我不想更改核心Umbraco表定义。

I found this reference which suggested extending the node document to expose the release date in C#, using: 我发现此参考建议使用以下方法扩展节点文档以使用C#公开发布日期:

public static string ReleaseDate(int nodeId) {
    Document d = new Document(nodeId);
    return d.ReleaseDate.ToString();
}

... but how do I translate that C# in xslt? ...但是如何在xslt中翻译C#? Rewriting the xslt as ascx macros is not an option. 不能将xslt重写为ascx宏。

You could use an XSLT extension. 您可以使用XSLT扩展名。 See this tutorial (http://www.nibble.be/?p=60), but I've adapted it here. 请参阅本教程(http://www.nibble.be/?p=60),但我在这里进行了调整。

  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. 将.NET代码放在一个程序集(称为扩展)中,该程序集已生成并复制到umbraco安装的bin文件夹中。 For example we'll put it in MyProject.dll 例如,我们将其放在MyProject.dll中
  2. Open the /config/xsltExtensions.config file. 打开/config/xsltExtensions.config文件。
  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: 在您的xslt中,添加对扩展名的引用,并排除前缀:

     <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: 您现在应该可以像使用任何umbraco.library方法一样使用该方法,例如:

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

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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