tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/246-set-variable-gather-upcoming-events-by-timestampCascade CMS: Discussion 2014-03-25T21:17:39Ztag:help-archives.hannonhill.com,2010-02-09:Comment/188999702012-09-20T19:17:17Z2012-09-20T19:17:17Zset variable- gather upcoming events by timestamp<div><p>Hi Sarah,</p>
<p>You should be able to use the <strong>DateTool</strong> to get
the current timestamp (of type <em>long</em>) and compare it to the
either the Page's metadata or a Date chooser in a Data
Definition.</p>
<p>Something like the following should compare the current system
date with a Date chooser field from the Data Definition:</p>
<pre>
<code>## Return the system's current time as the number of milliseconds.
#set ( $currentTime = $_DateTool.getSystemTime() )
## Get pages with a "thedate" that is greater than or equal to the current time.
#set ( $upcoming = $_XPathTool.selectNodes($contentRoot, "//system-page[system-data-structure/thedate >= " + $currentTime + "]") )</code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/188999702012-09-20T19:34:36Z2012-09-20T19:34:36Zset variable- gather upcoming events by timestamp<div><p>Hey Ryan!</p>
<p>I got the following error:</p>
<p>Velocity content invalid: Lexical error, Encountered: "+" (43),
after : "" at <em>unset</em>[line 34, column 148]</p>
<p>This is line 34:</p>
<pre>
<code>#set ( $upcoming = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-page[system-data-structure/sidebar/event-info/event-date >= " + $currtime + "]") )</code>
</pre>
<p>This is $currtime:</p>
<pre>
<code>#set ( $currtime = $_XPathTool.selectSingleNode($contentRoot, "/system-index-block/@current-time").value )</code>
</pre>
<p>I'll play around some more, but let me know what you think. It
could just be me staring at this for too long! (we are on v7.0.2,
upgrading to 7.0.4 on Sunday)</p>
<p>Thanks,<br>
Sarah</p></div>Sarah Johnson Litag:help-archives.hannonhill.com,2010-02-09:Comment/188999702012-09-20T19:52:16Z2012-09-20T19:52:16Zset variable- gather upcoming events by timestamp<div><p>Hm, guess it doesn't like the string concatenation. Let's try
the following:</p>
<pre>
<code>#set ( $upcoming = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-page[system-data-structure/sidebar/event-info/event-date >= ${currtime}]") )</code>
</pre></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/188999702012-09-20T20:18:01Z2012-09-20T20:18:01Zset variable- gather upcoming events by timestamp<div><p>That was valid! Thank you very much!</p>
<p>Is this the proper way to call a macro?...</p>
<pre>
<code>#macro ( showEvent $pgs )
...
#end
...
#set ( $featured = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-page[dynamic-metadata[value='Yes']]") )
#set ( $upcoming = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-page[system-data-structure/sidebar/event-info/event-date >= ${currtime}]") )
...
#if(${featured.size()} > 0)
<h3>Featured Events</h3>
#showEvent($featured)
#end</code>
</pre></div>Sarah Johnson Litag:help-archives.hannonhill.com,2010-02-09:Comment/188999702012-09-20T20:20:32Z2012-09-20T20:20:32Zset variable- gather upcoming events by timestamp<div><p>Glad to hear that worked. The macro and the call look right to
me.</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/188999702012-09-21T19:01:14Z2012-09-21T19:01:35Zset variable- gather upcoming events by timestamp<div><p>Hi Ryan,</p>
<p>Thanks for confirming! The reason I checked about the macro and
call was that the macro wasn't firing for me. I came in this
morning and the same macro (code untouched) was rendering content
no problem. I just encountered something similar today where I
added text in Velocity to display and the page has not updated. Is
this related to the caching in 7.x or the memory leak with
Velocity?</p>
<p>We're in 7.0.2, Windows 7 Firefox 15 and Chrome 21 both
displayed similar issues, even after browser cache was cleared.</p></div>Sarah Johnson Litag:help-archives.hannonhill.com,2010-02-09:Comment/188999702012-09-21T19:06:21Z2012-09-21T19:06:21Zset variable- gather upcoming events by timestamp<div><p>Ah yes, there is a <a href=
"https://hannonhill.jira.com/browse/CSI-413">known defect</a> with
Cascade 7.0.2 in which macros were caching and not being released
properly. This sounds like what might be causing the issue.
Upgrading to Cascade 7.0.3+ should fix this behavior.</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/188999702012-09-21T19:24:43Z2012-09-21T19:24:43Zset variable- gather upcoming events by timestamp<div><p>Oh good! We are updating to 7.0.4 over the weekend so that's
fine. Thanks so much Ryan!!!</p></div>Sarah Johnson Litag:help-archives.hannonhill.com,2010-02-09:Comment/188999702012-09-21T19:38:28Z2012-09-21T19:38:28Zset variable- gather upcoming events by timestamp<div><p>Not a problem, let us know if the upgrade doesn't take care of
that.</p>
<p>Have a good weekend!</p></div>Ryan Griffith