How to use multiple velocity templates?

Hi, I am developing a plugin for jira-server.
Since plugin getting bigger, I put everything to a single velocity file and I want to divide it to several files.

  <web-resource key="aresTestManagementPlugin-resources" name="aresTestManagementPlugin Web Resources"> 
    <dependency>com.atlassian.auiplugin:ajs</dependency>  
    <resource type="download" name="aresTestManagementPlugin.css" location="/css/aresTestManagementPlugin.css"/>  
    <resource type="download" name="aresTestManagementPlugin.js" location="/js/aresTestManagementPlugin.js"/>
    <resource type="download" name="run-dialog.js" location="/js/dialog.js"/>
    <resource type="velocity" name="view"  location="templates/run-dialog.vm"/>
    <resource type="download" name="images/" location="/images"/>
    <context>aresTestManagementPlugin</context> 
  </web-resource>

  <web-panel name="TestManagementOverview"
             i18n-name-key="test-management-overview.name"
             key="test-management-overview"
             location="atl.jira.view.issue.left.context"
             weight="200">
    <description key="test-management-overview.description">The TestManagementOverview Plugin</description>  
    <context-provider class="com.trendyol.aresTestManagementPlugin.TestManagement"/>  
    <resource name="view" type="velocity" location="templates/test-management-overview.vm"/>
<resource name="view2" type="velocity" location="templates/run-dialog.vm"/>
  </web-panel>

and I want to use run-dialog.vm file in test-management-overview.vm like below

$webResourceManager.requireResource("com.trendyol.aresTestManagementPlugin:aresTestManagementPlugin-resources")

<div id="content">
#include("run-dialog.vm")
</div>

But I got com.atlassian.templaterenderer.RenderingException: org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'run-dialog.vm' error. How can I properly use several velocity files for same view?

Hi,
I use #parse("/templates/component-versions-plugin-header.vm") . But, don’t know the difference between #include and #parse. Maybe you need to give full path starting with “/”.

Hi @Erdemnta

You can use #parse like said @denizoguz
The #parse directive allows you to include the content of another Velocity Template file within your current template. This is useful for breaking down complex views into manageable parts.

#parse("header.vm")
#parse("content.vm")
#parse("footer.vm")

You can also use #include
The #include directive is similar to #parse but is used for including raw files. It’s less commonly used for HTML content since #parse provides more functionality (variable interpolation). However, it can be useful for including non-Velocity files that don’t need processing.

#include("static/header.html")
#parse("content.vm")
#include("static/footer.html")

In your case, you have to use #parse :smile:

Fabien [Elements]

1 Like