Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Sep 23, 2009 @ 15:15
    Claushingebjerg
    0

    show next event i calender

    I have  an event calender, where i wnat to show the next upcoming event on the frontpage of a site.

    Im doing the following:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1']">

    <xsl:sort select="data [@alias = 'newsdate']" order="ascending"/>
    <xsl:if test="(umbraco.library:FormatDateTime(data[@alias='newsdate'],'yyyyMMdd') &gt;= umbraco.library:FormatDateTime(umbraco.library:CurrentDate(),'yyyyMMdd'))">   
    <xsl:if test="position() &lt;= 1">

    This is the event

    </xsl:if>
    </xsl:if>

    </xsl:for-each>

    But this only works if no events have passed the current date. if there was an event yesterday, the macro returns nothing...

    Any ideas?

  • dandrayne 1138 posts 2262 karma points
    Sep 23, 2009 @ 16:08
    dandrayne
    0

    What about using DateGreaterThanOrEqualToday

    umbraco.library:DateGreaterThanOrEqualToday($date) to see if the day is upcoming.

    The problem above is that it is the position() within the "for-each" loop that the condition (<= 1) is testing, so this will only work if the first event in your list also fits into your date requirements.

    The other way, using the same method as above, would be to move the date logic into the for-each loop. (untested code below!)

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1' and umbraco.library:FormatDateTime(data[@alias='newsdate'],'yyyyMMdd')
    &gt;=
    umbraco.library:FormatDateTime(umbraco.library:CurrentDate(),'yyyyMMdd')]">
  • Chris Koiak 700 posts 2626 karma points
    Sep 23, 2009 @ 16:10
    Chris Koiak
    0

    Could you make it a conditional select?

    The first condition is when there are events in the future... the second is when all events are in the past.

    Try something like

    <!-- Search and filter nodes -->
    <xsl:variable name="futureEvents" select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1' and (umbraco.library:FormatDateTime(data[@alias='newsdate'],'yyyyMMdd') &gt;= umbraco.library:FormatDateTime(umbraco.library:CurrentDate(),'yyyyMMdd')]">

    <xsl:choose>
    <xsl:when test="count($futureEvents) > 1">
    <xsl:for-each select="$futureEvents">
    <xsl:sort select="data [@alias = 'newsdate']" order="ascending"/>
    <xsl:if test="position() = 1">
    OUTPUT EVENT
    </xsl:if>
    </xsl:for-each>
    </xsl:when>
    <xsl:otherwise>
    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1']">
    <xsl:sort select="data [@alias = 'newsdate']" order="descending"/>
    <xsl:if test="position() = 1">
    OUTPUT EVENT
    </xsl:if>
    </xsl:for-each>
    </xsl:otherwise>
    </xsl:choose>
Please Sign in or register to post replies

Write your reply to:

Draft