This code shows the news and pages it. For the piece I am trying to add now, I have tried if statements which didn't work and for-each statements which all blew up in my face.
I tried that before thinking it sounded like what I needed... I keep getting
System.FormatException: String was not recognized as a valid DateTime
Any idea why that would be happenening? I have tried formatting the date and that doesn't seem to work, though I am not sure what exact format it is looking for. Any ideas?
If I do this: <xsl:for-each select="$articlePages[umbraco.library:DateGreaterThanOrEqualToday('06/17/2011')]"> it works... yay
but if I do this: <xsl:for-each select="$articlePages[umbraco.library:DateGreaterThanOrEqualToday(umbraco.library:FormatDateTime(newsDate, 'MM/dd/yyyy'))]"> it doesn't work... invalid date again
or this: <xsl:variable name="dateNews" select="umbraco.library:FormatDateTime(newsDate, 'MM/dd/yyyy')"/> <xsl:for-each select="$articlePages[umbraco.library:DateGreaterThanOrEqualToday($dateNews)]"> it doesn't work... invalid date again
I can't hardcode the date because it needs to change per news item, so what am I missing here to make this work?
If articleDate is a standard Date (or DateTime) property it should work. The only date format really worth storing is the xmlDate format (e.g., '2011-06-11T21:53:16+0200') - this will work with all the formatting functions AND it's sortable as just a string.
What you need to be careful of though, is that when you do something like this:
- the processor will call the function on ALL the matching $articlePages, whether they have a newsDate property or not; so maybe that's your problem - one of the pages doesn't have a newsDate property (or has a bad 'date' in it). This could easily happen if you add the newsDate property to a Document Type, after having already published pages based on the version without it.
You can try to safeguard against the missing property issue by doing this:
Return only news with start dates later than today
Posted before, but I wasn't clear and the system isn't letting me edit... so posting a new one here and trying to be more clear :)
Being new to XSLT and Umbraco... I am having difficulty trying to not show a news article after it is past today's date.
Here is the code I am using to show my news list...
<xsl:if test="$numberOfItems > 0"><ul id="newsList">
<xsl:for-each select="$articlePages">
<xsl:sort select="articleDate" order="ascending"/>
<xsl:if test="position() > $recordsPerPage * number($pageNumber) and
position() <= number($recordsPerPage * number($pageNumber) +
$recordsPerPage )">
<li>
<h3>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</h3>
<p class="articleDate">
<xsl:value-of select="umbraco.library:FormatDateTime(articleDate,'dd MMMM yyyy')"/>
</p>
<p>
<xsl:value-of select="articleSummary"/>
</p>
</li>
</xsl:if>
</xsl:for-each>
</ul>
<xsl:if test="$numberOfItems > $recordsPerPage">
<p id="pager">
<xsl:call-template name="pageNumbers">
<xsl:with-param name="pageIndex" select="1"/>
</xsl:call-template>
</p>
</xsl:if>
</xsl:if>
This code shows the news and pages it. For the piece I am trying to add now, I have tried if statements which didn't work and for-each statements which all blew up in my face.
Any help would be appreciated.
Thank you,
Tony
Hi Tony,
There's a couple of handy extension methods in umbraco.library for that, e.g.:
or:
/Chriztian
Thanks for the response Chriztian...
I tried that before thinking it sounded like what I needed... I keep getting
System.FormatException: String was not recognized as a valid DateTime
Any idea why that would be happenening? I have tried formatting the date and that doesn't seem to work, though I am not sure what exact format it is looking for. Any ideas?
So here is what I find wierd...
If I do this:
<xsl:for-each select="$articlePages[umbraco.library:DateGreaterThanOrEqualToday('06/17/2011')]">
it works... yay
but if I do this:
<xsl:for-each select="$articlePages[umbraco.library:DateGreaterThanOrEqualToday(umbraco.library:FormatDateTime(newsDate, 'MM/dd/yyyy'))]">
it doesn't work... invalid date again
or this:
<xsl:variable name="dateNews" select="umbraco.library:FormatDateTime(newsDate, 'MM/dd/yyyy')"/>
<xsl:for-each select="$articlePages[umbraco.library:DateGreaterThanOrEqualToday($dateNews)]">
it doesn't work... invalid date again
I can't hardcode the date because it needs to change per news item, so what am I missing here to make this work?
Thanks!
Hi Tony,
If articleDate is a standard Date (or DateTime) property it should work. The only date format really worth storing is the xmlDate format (e.g., '2011-06-11T21:53:16+0200') - this will work with all the formatting functions AND it's sortable as just a string.
What you need to be careful of though, is that when you do something like this:
- the processor will call the function on ALL the matching $articlePages, whether they have a newsDate property or not; so maybe that's your problem - one of the pages doesn't have a newsDate property (or has a bad 'date' in it). This could easily happen if you add the newsDate property to a Document Type, after having already published pages based on the version without it.
You can try to safeguard against the missing property issue by doing this:
This will ensure that the there is a newsDate property and it has a value other than pure whitespace.
/Chriztian
Seriously Chriztian... you are my hero. That was the issue, so I used your "safeguard" code and it worked like a charm.
Thank you very much... my headache is subsiding :)
Tony
Great - you're welcome,
One less problem in the world... :-)
/Chriztian
is working on a reply...