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.
Community moderators have prevented the ability to post new answers.
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.
I understand. This could work, but isn't there a possibility of using the API?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.