Quantcast

Functions

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Functions

Philippe de Rochambeau

Is there a way to create dynamic methods/functions in Velocity Templates?

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Functions

Mike Kienenberger
Depends what you need.

Take a look at # macros if the only output from the function is generated text.

http://velocity.apache.org/engine/releases/velocity-1.7/user-guide.html#Velocimacros


Otherwise, the way to do this is to create a new tool (which is any
java class with a zero-arg constructor aka POJO) and add it to your
toolkit (covered in the other thread and a bit complicated in your
case).  But the tool itself is as trivial as it sounds.

class FooTool {
      public Integer barFunction(Object x, String y, List z) {
           // return Integer.valueOf(...);
      }
}

Assuming FooTool is registered under tool name "foo", then use this in
your template.

${foo.barFunction(x, y, z)}

Look at the existing velocity tools (like math) if you need more examples.




On Thu, Feb 19, 2015 at 10:22 AM,  <[hidden email]> wrote:
>
> Is there a way to create dynamic methods/functions in Velocity Templates?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Functions

Erik Hatcher-4
In reply to this post by Philippe de Rochambeau
You mean like the macros?  Since you’re in Solr-land, look at the VM_global_library.vm file and how those pieces are used.  (it’s a bit uglier than it should be in the Solr example macro library, but should give you some insight there).



Erik Hatcher, Senior Solutions Architect
http://www.lucidworks.com <http://www.lucidworks.com/>




> On Feb 19, 2015, at 10:22 AM, [hidden email] wrote:
>
>
> Is there a way to create dynamic methods/functions in Velocity Templates?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Functions

Philippe de Rochambeau
Ah, I never thought of using macros as methods/functions. Thanks.

----- Mail original -----
De: "Erik Hatcher" <[hidden email]>
À: "Velocity Users List" <[hidden email]>
Envoyé: Jeudi 19 Février 2015 16:43:43
Objet: Re: Functions

You mean like the macros?  Since you’re in Solr-land, look at the VM_global_library.vm file and how those pieces are used.  (it’s a bit uglier than it should be in the Solr example macro library, but should give you some insight there).



Erik Hatcher, Senior Solutions Architect
http://www.lucidworks.com <http://www.lucidworks.com/>




> On Feb 19, 2015, at 10:22 AM, [hidden email] wrote:
>
>
> Is there a way to create dynamic methods/functions in Velocity Templates?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Functions

Nathan Bubna
(shaking his head)

please use a tool object, if at all possible. using macros as functions
gives me the willies. :)  they're meant to clean/simplify repetition of
content. just because they can be used as functions, doesn't mean they
should be. things can get ugly down that road. :)

On Thu, Feb 19, 2015 at 7:47 AM, <[hidden email]> wrote:

> Ah, I never thought of using macros as methods/functions. Thanks.
>
> ----- Mail original -----
> De: "Erik Hatcher" <[hidden email]>
> À: "Velocity Users List" <[hidden email]>
> Envoyé: Jeudi 19 Février 2015 16:43:43
> Objet: Re: Functions
>
> You mean like the macros?  Since you’re in Solr-land, look at the
> VM_global_library.vm file and how those pieces are used.  (it’s a bit
> uglier than it should be in the Solr example macro library, but should give
> you some insight there).
>
>
> —
> Erik Hatcher, Senior Solutions Architect
> http://www.lucidworks.com <http://www.lucidworks.com/>
>
>
>
>
> > On Feb 19, 2015, at 10:22 AM, [hidden email] wrote:
> >
> >
> > Is there a way to create dynamic methods/functions in Velocity Templates?
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Loading...