roller-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mullan Colm" <>
Subject obtaining values from a new VelocityContext
Date Mon, 15 Sep 2008 10:37:18 GMT
Hi Folks,


I would like to obtain the user name for comments from a cookie file
(this will be obtained from a java function), lets not worry about how
the name is pulled from the cookie I have that under control. But I need
to know how in Roller we can display content from a custom java method,
For example consider the helloworld example using a different


If I define a new class i.e.


import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
public class HelloWorld
    public static void main( String[] args )
        throws Exception
        /*  first, get and initialize an engine  */
        VelocityEngine ve = new VelocityEngine();
        /*  next, get the Template  */
        Template t = ve.getTemplate( "helloworld.vm" );
        /*  create a context and add data */
        VelocityContext context = new VelocityContext();
        context.put("name", "World");
        /* now render the template into a StringWriter */
        StringWriter writer = new StringWriter();
        t.merge( context, writer );
        /* show the World */
        System.out.println( writer.toString() );     
And then add the following line to my weblog.wm template file
Hello $name!  Welcome to Velocity!
Name is not populated. How do we tell Roller to use the different
VelocityContext in this case?
Thanks Colm


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message