Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to render html tags on Velocity template?

Hi, I'm developing a plugin that gets form values and displays them on a new page. The form values contain html tags. However, when I use ${variable-name}, the tags are not rendered. What do I do to render the html elements?


My action class:

package com.example.plugin;
import com.atlassian.confluence.core.ConfluenceActionSupport;
import com.opensymphony.xwork.Action;
public class ComparatorPluginResultAction extends ConfluenceActionSupport {        
private String pageVersion1;    
private String pageVersion2;
    public String execute() throws Exception {        return Action.SUCCESS;    }
    public String getPageVersion1() {        return this.pageVersion1;    }
    public String getPageVersion2(){        return this.pageVersion2;    }
    public void setPageVersion1(String pageVersion1){        this.pageVersion1 = pageVersion1;    }
    public void setPageVersion2(String pageVersion2){        this.pageVersion2 = pageVersion2;    }


My velocity template:

<title>Compare Results</title>        
<meta name="decorator" content="atl.general" />        
<div id="compare-div">            
<div id="col1">${pageVersion1}</div>            
<div id="col2">${pageVersion2}</div>        

1 answer

1 accepted

This seems to be correct in general, but you need to put some values to "pageVersion1" and "pageVersion2" variables in your "execute" method

And for HTML tags you need to use @HtmlSafe annotation



Hey Alex, thanks for the reply. I found a solution before seeing your answer. 

I added these 2 lines in the velocity template:

#set($pageVersion1WithHtml = $pageVersion1) <!-- to render html elements -->    
#set($pageVersion2WithHtml = $pageVersion2) 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

🏑 Atlympic Event: Confluence

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

170 views 6 8
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you