Hi,
I am trying to write a user macro that receives an integer as a parameter, and use it as an integer in a Velocity Range (for example) - I wrote a small macro -
## This is an example macro
## @noparam
#set ($maxndx = 20)
#set( $mindx = 12)
#foreach ($ndx in [$mindx..$maxndx])
$ndx
#end
That works fine - printing out the numbers from 12 to 20
But when I add a parameter (whose type is integer) and use its value (as the upper limit):
## @Param uplimit:title=Item Limit|type=int|desc=maximum number|default=25
#set ($maxndx = $paramuplimit)
The foreach statement doesn't seem to execute - there is no output.
I get similar phenomena when I try to use if-statments comparing an integer to a parameter value.
So how do I use integers as parameters to a User Macro?
Thanx
There is a trick to this.
#set($paramuplimit = $generalUtil.convertToInteger("$paramuplimit"))
Thanx - that seems to work - are there similar converters to change a date (taken from a page - for example the creation date) into an integer?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When you say change date into an integer do you want it in epoch time? If so, what do you want to accomplish with it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Yes, the intention was to change to Epoch time, but I found the answer in the meantime - using the Date.getTime() method. The purpose was to compare two times, which I accomplished using the before/after methods.
Thanx for the reply.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The latest version of VelocityUtil class doesn't include the convertToInteger() method, so please try the below code snippet to convert string values to integer:
#set ($Integer = 0) #set ($paramuplimit=$Integer.parseInt($paramuplimit))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.