Where to put velocity template for macro plugin?

Chong Jing Hong July 1, 2021

I want to render a velocity template for my macro plugin. I placed the template in a folder under the resources folder. However, whenever I try to use the macro, this error shows up:

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource path to velocity template

I even tried specifying the absolute path and it didn't work.

 

My code:

import com.atlassian.confluence.content.render.xhtml.ConversionContext;import com.atlassian.confluence.macro.Macro;import com.atlassian.confluence.macro.MacroExecutionException;import com.atlassian.confluence.util.velocity.VelocityUtils;import com.atlassian.confluence.renderer.radeox.macros.MacroUtils;
import java.util.Map;
public class MermaidLiveEditorMacro implements Macro {
    public String execute(Map<StringString> map, String s, ConversionContext conversionContext) throws MacroExecutionException {        
// do something with params ...        
String code = map.get("Code");        
String sampleDiagrams = map.get("Sample Diagrams");
        Map context = MacroUtils.defaultVelocityContext();        
context.put(map.get(
"Code"), code);        
context.put(map.get(
"Sample-diagrams"), sampleDiagrams);        
return VelocityUtils.getRenderedTemplate(absolute path to velocity template, context);    
}

     public BodyType getBodyType() { return BodyType.PLAIN_TEXT; }
     public OutputType getOutputType() { return OutputType.BLOCK; }}

 

 

1 answer

0 votes
Fabian Lim
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 17, 2021

Hi @Chong Jing Hong

Take a look at this post , you have to ensure that the resource is added to the atlassian-pluin.xml file.

Thanks 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events