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

Passing variables to PageTemplate in confluence

Héctor González May 15, 2014

Hello everyone, I'm having problems with the use of variables from a template when creating a confluence page programmatically.

I mean, I'm developing a confluence plugin that is going to create a page from a template.

If I create the page myself, it works, but if I try to use a template and then insert variables to that template, it doesn't. I have this template created by an admin, and it has some variables defined in it. All I want to do is being able to insert values to those variables programmatically.

I'm using the PageTemplateManager interface and the PageTemplate class in a java servlet.

With them, I can access my template and create my page with all the content but the variables.

In order to insert them I was using the pageTemplateManager.mergeVariables or the pagetemplateManager.insertVariables, but, either I don't know how to use them or they are not suitable for this purpose.

I'm saying that I don't know how to use them cause when I search the api, there is no text saying what is exactly the thing they do.

So if anyone has an answer to how to use this methods or how to map the variables (with a context for example, but that is not valid here) please help me.

Thank you all.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Yagnesh Bhat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 17, 2014

Try this : Make the placeholders in the user template as plain text. The palceholders can be something like $placeholder. When you type anything with a dollar, confluence offers you an option to make it some kind of a variable surrounded with a green background - avoid that by pressing escape key! Keep it stricly as plain text.

Now, create a user macro in java that takes the user template as the input and the value you want to replace the placeholder with as input parameters. Refer to the confluence tutorials on creating user macros in java to get an idea. Then in the execute method of the macro, do a simple java replace() , to replace everything that has $placeholder in the user macro with the values.

Héctor González May 20, 2014

I understand. This could work, but isn't there a possibility of using the API?

Yagnesh Bhat
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 21, 2014

Well, you would simply use the simple Java' string Replace in the execute method of the macro and replace the placeholders with whatever values you want. Should be pretty simple.... i dont think we would need any specialized api for that ...

Héctor González May 22, 2014

I understand, and it works, but I have quite a few variables and the creation of the page is very slow cause I have to replace a String a lot of times. Maybe if there was another possibility this would be faster.

Héctor González May 26, 2014

Well, as there are no more suggestions, I will approve this response. At the end I'm using it, and as I said above, it works.

TAGS
AUG Leaders

Atlassian Community Events