The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Change template content based on user input in variables

Axel Holene
Contributor
June 19, 2017

I have a template which have a couple of variables, such as

 

$tempTitle (String)
$tempQuality (list of Strings)

where $tempTitle is just a string and $tempQuality is a list variable given in the template. 

 

Now, I have spent a lot of time trying to figure out how I'm supposed to do this, and my employer should probably kill me for spending so much time on just nifty feature...

I'm trying to rename the title with the code given by Nelson in this answer, which works on $tempTitle. However, I'm not able to write more code that actually are able to evaluate the $tempQuality and include this evaluation in the title. 

My code as it stands now (not working)

 

## @noparams

<script>
$("input[name='variableValues.tempQuality']").change(function(){
  var KEnr = $(this).val();
});
$("input[name='variableValues.tempTitle']").change(function(){
    console.log($(this).val());
    $("form[name='filltemplateform']").find("input[name='title']").val($(this).val())
})
</script>

I completely fail to understand how the Confluence macros handle data from template variables, can someone please enlighten me? I'm going completetly bonkers over how riddiculously difficult it is to have some sophisticated dynamic content in Confluence. 

 

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Stephen Deutsch
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 Champions.
June 22, 2017

Hi Axel, maybe try this:

<script>
AJS.toInit(function() {
 if (document.URL.indexOf("createpage-entervariables.action?templateId=132939777") !== -1) {
  var variableNameElement = $('input[name="variableValues.variableName"]:visible');
  variableNameElement.on("change", function() {
   $("input[name=title]").attr("value", variableNameElement.val() + " - " + (new Date()).toISOString().substring(0,10));
  });
 }
});
</script>

Change 132939777 to whatever your template ID is (when you load the template, it's shown in the URL) and change all instances of "variableName" whatever your variable name is. I included also inserting the current date in the page. You seem fairly familiar with Javascript, so you can customize it as you want.

Unfortunately, including it in a user macro won't work. You'll have to insert it in the Global Custom HTML to get it to work.

TAGS
AUG Leaders

Atlassian Community Events