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

<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

0 vote
Stephen Deutsch Community Champion Jun 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.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

912 views 23 12
Join discussion

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