1

I am loading up a vm tgemplate with velocity and chnaging some of the parameters I have around 10 parameters that can change in my template

For the following portion of my template

window.location = "$html5Dirhtml5/index.html?page=$pageNumber"

I get this output

window.location = "$html5Dirhtml5/index.html?page=1"

Any idea why velocity is not converting the html5Dir attribute but it is setting the page?

The attributes definitely exist in the attributes passed to velocity, I have checked this My velocity code is as follows

public static StringWriter generateTextFromTemplate(String templateFile, Map<String, String> params) {
    LOG.debug("Entered generateTextFromTemplate - templateFile:{}", templateFile);


    StringWriter writer = null;
    try {
        VelocityEngine velocityEngine = new VelocityEngine();
        velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); 
        velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        velocityEngine.init();

        VelocityContext velocityContext = new VelocityContext();

        for (Map.Entry<String, String> entry : params.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            velocityContext.put(key, value);
            LOG.error("key:{}, value:{}", key, value);
        }

        //  get the Template 
        Template template = velocityEngine.getTemplate(templateFile);

        //  now render the template into a Writer 
        writer = new StringWriter();
        template.merge( velocityContext, writer );

    } catch (Exception e) {
       LOG.error("{}", e);
       writer = null;
    }

    return writer;
}

1 Answer 1

1

First of all, check that there is an actual html5Dirhtml5 parameter. If that isn't the parameter you want and it's html5Dir, then you need to use the form ${html5Dir} in the template to demarcate what the actual name is.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Tassos that was the notation I was looking for. Works as expected now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.