Change template content based on user input in variables

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

  var KEnr = $(this).val();

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

Hi Axel, maybe try this:

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));

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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Dec 18, 2018 in Confluence Cloud

Happy holidays from our team to yours!

Hi Community!  2018 was filled with changes for our team, both big and small, and we've taken a lot of time to both celebrate our wins and recognize areas of improvement. One thing that we're a...

459 views 3 18
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you