Copied to clipboard

Flag this post as spam?

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


  • Bruce Clark 56 posts 80 karma points
    Dec 17, 2010 @ 02:16
    Bruce Clark
    0

    Don't want current date if blank on umbraco:item

    Hi All,

    I have an event implementation that I've written, everything is smashing except when I'm outputing individual events onto a template. I have an eventDate and eventEndDate, obviously end date should only show if it exists, otherwise the event is only one day long. Here's the issue:

     

    <umbraco:Item field="eventDate" insertTextBefore="&lt;h3 class=&quot;left&quot;&gt;" insertTextAfter="&lt;/h3&gt;" formatAsDate="true" runat="server"></umbraco:Item>
    <umbraco:Item field="eventEndDate" insertTextBefore="&lt;h3&gt;- " insertTextAfter="&lt;/h3&gt;" formatAsDate="true" runat="server"></umbraco:Item>

    Here's the issues, eventEndDate by default returns the current date if the eventEndDate doesn't exist. I dont want it to return anything. It makes no sense that having formatAsDate turned on would make it spit out the current date when the field is empty. All other umbraco:item behavior doesn't do this and will just not show if the field it is targeting is empty, unless an alternate field has been speicifed. Why is this instance different, and how can I fix it?

     

    Thanks so much!

    -Bruce

  • Chris Koiak 700 posts 2626 karma points
    Dec 17, 2010 @ 11:05
    Chris Koiak
    0

    Hi Bruce,

    You're right, that is odd behaviour.

    Looks like you need to create an xslt macro to solve this. The xslt would look something like

    <xsl:if test="string-length($currentPage/eventDate) > 0">
    <h3><xsl:value-of select="umbraco.library:FormatDateTime(
    $currentPage/eventDate,'dd/MM/yyyy')"/></h3>
    </xsl:if>

    Enjoy!

    Chris

     

  • Bruce Clark 56 posts 80 karma points
    Dec 17, 2010 @ 17:50
    Bruce Clark
    0

    Yeah, I've been able to do this with a Macro. Thanks. I was really more curious why in the world it's set up like this. Having the default functionality of umbraco:item's not ouput anything if the field is blank EXCEPT for dates is ludicrous.

    There's no reason someone would want the current date if the date they were trying to access wasn't available. Really I'm completely confused to why it was done this way.

    -Bruce

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 17, 2010 @ 20:11
    Tom Fulton
    0

    Not sure why, but it looks like umbraco:Item is specifically hardcoded in to use today's date if empty and format as date is selected.

    Just another workaround without using a macro - uncheck format as date and use inline xslt to format it:

    <umbraco:Item field="fieldName" runat="server" Xslt="umbraco.library:FormatDateTime({0},'MM/dd/yyyy')"></umbraco:Item>
  • Bruce Clark 56 posts 80 karma points
    Dec 17, 2010 @ 20:14
    Bruce Clark
    0

    Good solution. I've submitted an issue on codeplex for this.

    http://umbraco.codeplex.com/workitem/29755

Please Sign in or register to post replies

Write your reply to:

Draft