Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jos Huybrighs 23 posts 55 karma points
    Jan 13, 2011 @ 09:25
    Jos Huybrighs
    0

    Attempt to create a FormattedDateTime macro/xslt

    I am trying to make a macro/xslt that has a 'date' and 'formatString' parameter as input parameters to emit a date string in any format I like according to the .NET format string syntax (e.g. "dd MMMM", ..).

    The invocation of the macro looks as follows (e.g. for @createDate):

    <div class="Date">
      <umbraco:Macro Alias="FormattedDateTime"
                    
    date='<umbraco:Item field="createDate" runat="server" />'
                     
    format="dd MMMM"
                     
    runat="server" />
    </div>

    My XSLT looks as follows:

    ...
    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:variable name="date" select="/macro/date" />
    <xsl:variable name="formatString" select="/macro/formatString" /> 

    <xsl:template match="/">

      <xsl:value-of select="umbraco.library:FormatDateTime($date, $formatString)"/>

    </xsl:template
    >
    ...




    The problem I have is how to pass a umbraco 'date' attribute/property to the macro. E.g. what should I use as the parameter type for 'date'. It currently is set to 'text' which doesn't seem right to me.

    With the above code nothing is returned in the XSLT because $date apparently is not holding the date that I had expected to be passed with the umbraco:item parameter. When I output $date in the XSLT  file it shows the following:

    <umbraco:Item field="createDate" runat="server"></umbraco:Item>

    Very strange!

    Anyone can help me on this?

    Thanks.

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Jan 13, 2011 @ 09:39
    Richard Soeteman
    0

    I think this is what you want

    <umbraco:Macro Alias="FormattedDateTime"
                     
    date="[#createDate]
    " 
                    
     
    format="dd MMMM"
                   
     
    runat="server" /
    >

     A parameter can be passed from your document using the [#property name] syntax. If you want to pass a recursive property use [$property name]

    Cheers,

    Richard

  • Jos Huybrighs 23 posts 55 karma points
    Jan 13, 2011 @ 09:59
    Jos Huybrighs
    0

    Thanks Richards. This indeed works. I didn't try this syntax because I thought it could only be used for 'data' aliases, not for node attributes. 

Please Sign in or register to post replies

Write your reply to:

Draft