How to include an inner Velocity Template within a Velocity Template

Najjar _Innovura_
Atlassian Partner
April 8, 2020

I would like to reuse a template inside multiple other template and I looked in Apache Velocity Template and I found what I am looking for

 

## Load the file one.vm into this template
#include( "one.vm" )

However when I tried it in Jira it didn't work. Most probable because of the path

So I tried to change the path to the vm by trying all of the below

#include("./src/main/resources/templates/one.vm")
#include("src/main/resources/templates/one.vm")
#include("./one.vm")
#include("templates/one.vm")

 

 but I keep getting an exception. Does anyone know how to achieve this in Jira?

 

Exception

Exception getting message body from Velocity: org.apache.velocity.exception.VelocityException: Cannot process content resource
[INFO] [talledLocalContainer] org.apache.velocity.exception.VelocityException: Cannot process content resource
[INFO] [talledLocalContainer] at org.apache.velocity.runtime.resource.ContentResource.process(ContentResource.java:89)
[INFO] [talledLocalContainer] at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:446)
[INFO] [talledLocalContainer] at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:354)
[INFO] [talledLocalContainer] at org.apache.velocity.runtime.RuntimeInstance.getContent(RuntimeInstance.java:1444)
[INFO] [talledLocalContainer] at org.apache.velocity.runtime.directive.Include.renderOutput(Include.java:229)
[INFO] [talledLocalContainer] at org.apache.velocity.runtime.directive.Include.render(Include.java:155)
[INFO] [talledLocalContainer] at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:175)
[INFO] [talledLocalContainer] at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
[INFO] [talledLocalContainer] at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:87)
[INFO] [talledLocalContainer] at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
[INFO] [talledLocalContainer] at org.apache.velocity.Template.merge(Template.java:328)
[INFO] [talledLocalContainer] at org.apache.velocity.Template.merge(Template.java:235)
[INFO] [talledLocalContainer] at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:381)

 

1 answer

1 accepted

3 votes
Answer accepted
Jack Nolddor _Sweet Bananas_
Atlassian Partner
April 8, 2020

Hi

Have you tried?

#parse("/templates/one.vm")

Regards

Najjar _Innovura_
Atlassian Partner
April 8, 2020

Thank you @Jack Nolddor _Sweet Bananas_ 

 

Works like a charm!

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events