Copied to clipboard

Flag this post as spam?

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


  • Dave 16 posts 36 karma points
    Jul 19, 2010 @ 23:19
    Dave
    0

    Date format / Macro access to page Properties

    I need to use a property (startDate) from the template in a Macro.

    I can't confirm if the problem I'm having is that the date isn't read, or if there's something wrong with the XSLT.

    Here is the bulk of my XSLT:

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

      <xsl:param name="currentPage"/>
      <xsl:variable name="sDate" select="$currentPage/data [@alias = 'startDate']" />

    <xsl:template match="/">

    <!-- start writing XSLT -->
    <time class="calendar">
      <xsl:attribute name="datetime">
        <xsl:value-of select="umbraco.library:FormatDateTime($sDate, 'yyyy-MM-dd')"/>
      </xsl:attribute>
      <span>
        <xsl:variable name="monthname" select="umbraco.library:FormatDateTime($sDate,'MMM')" />
        <xsl:value-of select="$monthname"/>
      </span>
      <xsl:value-of select="umbraco.library:FormatDateTime($sDate, 'd')"/>
    </time>
    </xsl:template>

    I'm running Umbraco 4.5, and have the following macro parameter:

    And this is the code in my template:

    <umbraco:Macro startDate="startDate" Alias="EventDate" runat="server"></umbraco:Macro>

     

    Any help is greatly appreciated.

  • Dimitris Tsoukakis 33 posts 59 karma points
    Jul 20, 2010 @ 12:09
    Dimitris Tsoukakis
    0

    First of all, I think that its a good idea to use another variable to hold the macro parameter value, like following:

    Try this

     

    <xsl:variable name="macroParam" select="/macro/startDate" />

    The reason that you use a propertyTypePicker is to allow you to define different properties on different templates.


    Of course my comment doesn't solves your problems. Try rename the macro parameter so that it has a different name with any of the document type properties. There may be a conflict.

    What do you get with this:

    <xsl:value-of select="$sDate"/>

    Do you get an ugly date or just nothing.

     

     

     

     

  • Dave 16 posts 36 karma points
    Jul 20, 2010 @ 19:14
    Dave
    0

    Right now, the text "startDate" is returned.

  • Josh Townson 67 posts 162 karma points
    Jul 21, 2010 @ 13:31
    Josh Townson
    0

    Hi Dave, your Macro insert code doesn't look like what you might want

    <umbraco:Macro startDate="startDate" Alias="EventDate" runat="server"></umbraco:Macro>

    will pass the textstring startDate into your xslt under /macro/startDate.

    Do you have a page property called startDate on the node you are using and is it filled in? ie what does this code produce (when placed directly inside the <template match="/">...:

    <xsl:value-of select="$currentPage/data [@alias = 'startDate']" />
  • Dave 16 posts 36 karma points
    Jul 21, 2010 @ 16:23
    Dave
    0

    Thanks Josh,

    You are correct, in fact, what I needed, or what worked at least was this:

    <umbraco:Macro eventDate="[#startDate]" Alias="EventDate" runat="server"></umbraco:Macro>

    Followed by the following macro code:

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

    <xsl:param name="currentPage"/>
    <xsl:variable name="sDate" select="/macro/eventDate" />
    <xsl:template match="/">
    <!-- start writing XSLT -->
    <
    time class="calendar" datetime="{umbraco.library:FormatDateTime($sDate, 'yyyy-MM-dd')}">
      <span>
        <xsl:variable name="monthname" select="umbraco.library:FormatDateTime($sDate,'MMM')"/>
        <xsl:value-of select="$monthname"/>
      </span>
      <xsl:value-of select="umbraco.library:FormatDateTime($sDate,'dd')"/>
    </time>
    </xsl:template>
    </xsl:stylesheet>

    Which resulted in the output that I was looking for!

Please Sign in or register to post replies

Write your reply to:

Draft