You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Colin Chalmers <co...@maxware.nl> on 2002/10/21 21:09:02 UTC
Velocity template
Hi all,
Using Velocity with Tubine and would like to know if there's somewhere I can set a *global* variable which is applicable to (almost) all templates. I want to set a date format which I can use to show the date in a number of templates. I tried to add a #set statement to the global_macros file but things went wrong. Any ideas? Can't imagine I have to add #set to each and every template.
Any help appreciated.
/Colin
Re: Velocity template
Posted by Rodney Schneider <ro...@actf.com.au>.
Hi Colin,
You could use a global pull tool and a FieldMethodizer to accomplish this,
like the way they do it in Scarab.
Have a look at:
org.tigris.scarab.util.ScarabConstants
org.tigris.scarab.tools.ScarabGlobalTool
Because there is a getConstant() method in the global pull tool, you can then
access these constants from any template like so:
$globaltool.Constant.CONSTANT_NAME
Hope that helps,
-- Rodney
On Tue, 22 Oct 2002 08:23, you wrote:
> Hi David,
>
> Thx for the reply. We've already built a pull tool for working with Dates.
> One of the methods we have allows us to pass a Date and a format for
> display purposes. In our application we need to show the date in at least 3
> different but similiar formats. In order to help me I thought it would be
> easy to set something like
>
> #set $DateOne = "dd/MM/yy"
> #set $DateTwo = "dd-MM-yyyy"
> #set $DateThree = "dd/MM/yyyy HH:mm"
>
> as globals and passing the String to the Pull tool such as
>
> PullTool(ActualDate, $DateOne)
>
> which should show something like the following on the screen
>
> 18/11/68
>
> /colin
>
>
> ----- Original Message -----
> From: "David Worms" <da...@simpledesign.com>
> To: "Turbine Users List" <tu...@jakarta.apache.org>
> Sent: Monday, October 21, 2002 9:14 PM
> Subject: Re: Velocity template
>
> > What you need is to create a tool. It is pretty easy and work very well.
> > Here is an example:
> >
> > public class DateTool implements ApplicationTool
> > {
> > private static final Log log = LogFactory.getLog( Date.class );
> >
> > private String date = null;
> >
> > /**
> > * Initialize the UIManager object.
> > *
> > * @param data This is null, RunData or User depending upon
> > specified tool scope.
> > */
> > public void init(Object data)
> > {
> > Date d = new GregorianCalendar().getTime();
> > DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
> > this.date = df.format(d);
> > }
> >
> > public String getNow()
> > {
> > return date;
> > }
> >
> > /**
> > * do nothing
> > */
> > public void refresh()
> > {
> > }
> >
> > }
> >
> > You can go to the pool how-to to see how to configure your TR.prop file
> >
> > David Worms
> >
> > On Monday, October 21, 2002, at 12:09 PM, Colin Chalmers wrote:
> > > Hi all,
> > >
> > > Using Velocity with Tubine and would like to know if there's somewhere
> > > I can set a *global* variable which is applicable to (almost) all
> > > templates. I want to set a date format which I can use to show the
> > > date in a number of templates. I tried to add a #set statement to the
> > > global_macros file but things went wrong. Any ideas? Can't imagine I
> > > have to add #set to each and every template.
> > >
> > > Any help appreciated.
> > >
> > > /Colin
> >
> > --
> > To unsubscribe, e-mail:
>
> <ma...@jakarta.apache.org>
>
> > For additional commands, e-mail:
>
> <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Velocity template
Posted by Colin Chalmers <co...@maxware.nl>.
Hi David,
Thx for the reply. We've already built a pull tool for working with Dates.
One of the methods we have allows us to pass a Date and a format for display
purposes. In our application we need to show the date in at least 3
different but similiar formats. In order to help me I thought it would be
easy to set something like
#set $DateOne = "dd/MM/yy"
#set $DateTwo = "dd-MM-yyyy"
#set $DateThree = "dd/MM/yyyy HH:mm"
as globals and passing the String to the Pull tool such as
PullTool(ActualDate, $DateOne)
which should show something like the following on the screen
18/11/68
/colin
----- Original Message -----
From: "David Worms" <da...@simpledesign.com>
To: "Turbine Users List" <tu...@jakarta.apache.org>
Sent: Monday, October 21, 2002 9:14 PM
Subject: Re: Velocity template
> What you need is to create a tool. It is pretty easy and work very well.
> Here is an example:
>
> public class DateTool implements ApplicationTool
> {
> private static final Log log = LogFactory.getLog( Date.class );
>
> private String date = null;
>
> /**
> * Initialize the UIManager object.
> *
> * @param data This is null, RunData or User depending upon
> specified tool scope.
> */
> public void init(Object data)
> {
> Date d = new GregorianCalendar().getTime();
> DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
> this.date = df.format(d);
> }
>
> public String getNow()
> {
> return date;
> }
>
> /**
> * do nothing
> */
> public void refresh()
> {
> }
>
> }
>
> You can go to the pool how-to to see how to configure your TR.prop file
>
> David Worms
>
> On Monday, October 21, 2002, at 12:09 PM, Colin Chalmers wrote:
>
> > Hi all,
> >
> > Using Velocity with Tubine and would like to know if there's somewhere
> > I can set a *global* variable which is applicable to (almost) all
> > templates. I want to set a date format which I can use to show the
> > date in a number of templates. I tried to add a #set statement to the
> > global_macros file but things went wrong. Any ideas? Can't imagine I
> > have to add #set to each and every template.
> >
> > Any help appreciated.
> >
> > /Colin
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Velocity template
Posted by David Worms <da...@simpledesign.com>.
What you need is to create a tool. It is pretty easy and work very well.
Here is an example:
public class DateTool implements ApplicationTool
{
private static final Log log = LogFactory.getLog( Date.class );
private String date = null;
/**
* Initialize the UIManager object.
*
* @param data This is null, RunData or User depending upon
specified tool scope.
*/
public void init(Object data)
{
Date d = new GregorianCalendar().getTime();
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
this.date = df.format(d);
}
public String getNow()
{
return date;
}
/**
* do nothing
*/
public void refresh()
{
}
}
You can go to the pool how-to to see how to configure your TR.prop file
David Worms
On Monday, October 21, 2002, at 12:09 PM, Colin Chalmers wrote:
> Hi all,
>
> Using Velocity with Tubine and would like to know if there's somewhere
> I can set a *global* variable which is applicable to (almost) all
> templates. I want to set a date format which I can use to show the
> date in a number of templates. I tried to add a #set statement to the
> global_macros file but things went wrong. Any ideas? Can't imagine I
> have to add #set to each and every template.
>
> Any help appreciated.
>
> /Colin
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>