Filtering auto slot content

Good morning

We have an auto index page, in which we want to provide a specific header for a slot item that matches the current date. In the auto index velocity template, i set up the following bindings:
$current_issue_day = $tools.date.getDay()
$current_issue_month = $tools.date.getMonth() + 1
$current_issue_year = $tools.date.getYear()

within the slot loop (#foreach($relresult in $sys.currentslot.relresults ))
i set the following variables:
#set($month_display = $relresult.getNode().getProperty(“rx:src_creation_date”).string.substring(5,7))
#set($day_display = $relresult.getNode().getProperty(“rx:src_creation_date”).string.substring(8,10))
#set($year_display = $relresult.getNode().getProperty(“rx:src_creation_date”).string.substring(0,4))

where src_creation_date is in the format yyyy-MM-dd

I then have the following check:
#if($year_display == $current_issue_year)
display a
#elseif
display b
#end

the first check on the if statement is never passing, eventhough when i output the variables, they are the same value. one thing i noticed is that the value set in the binding is java.lang.integer, and the variable set in the loop is a string…would this cause the check to fail? if so, is there a way to check a string and integer?

Yes

In 6.5.2, one way would be to convert the string into an integer, using $tools.math.toInteger($year_display). Another would be to convert the integer to a string, using $current_issue_year.toString(). Or do it all in java.util.Calendar objects, comparing using the methods designed for the purpose (not simply $obj1 == $obj2)

Thanks, that did it!

A related question: when i extract the month value from the source creation date it is formatted as “03” for march. however, the $tools.date.getMonth() + 1 function returns “3”…is there a way to get the function to return the month in 2-digit format?

Not with your method of extracting substrings. Check out this thread for tips on how to handle it using calandar objects.

Thanks Andrew

That post helped, I have updated my variable call to be:
#set($calmonth = $tools.date.toCalendar($relresult.getNode().getProperty(“rx:src_creation_date”).Date))
The page output of this variable:
java.util.GregorianCalendar[time=1237521600000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id=“US/Eastern”,offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=US/Eastern,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2009,MONTH=2,WEEK_OF_YEAR=12,WEEK_OF_MONTH=3,DAY_OF_MONTH=20,DAY_OF_YEAR=79,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=-18000000,DST_OFFSET=3600000]

My question now is how do I output one of the calendar properties (e.g. DAY_OF_WEEK). I tried setting another variable:
#set($dow = $tools.date.getCalendar($calmonth).DAY_OF_WEEK)
but on output it does not resolve to anything, it just shows $dow

Thanks
Raj

I actually got it using #set($dow = $calmonth.get(7))
where 7 is the constant value for DAY_OF_WEEK

for reference the constant value list is at:
http://java.sun.com/j2se/1.5.0/docs/api/constant-values.html

thanks!

Sorry, you cannot use any of the “static” properties or methods of Java objects in a Velocity template in Rhythmyx 6.5.2. But you don’t need to in this case. The $tools.date object is not the calendar object representing your date/time. It is a means for accessing methods described here for creating, reading and setting calendar objects. So, you could do…


#set($now = $tools.date.getCalendar())##
#set($created = $tools.date.toCalendar($sys.item.getProperty("rx:src_creation_date").Date))##
#if($tools.date.getDay($now) == $tools.date.getDay($created) && $tools.date.getMonth($now) == $tools.date.getMonth($created) && $tools.date.getYear($now) == $tools.date.getYear($created))##
  THIS ITEM WAS CREATED TODAY
#end##

There are probably better ways of doing it.