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

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 Leaders.
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.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, confluence whiteboards, whiteboard templates, template contest, visual collaboration, atlassian learning, confluence community, brainstorming tools, agile planning, team productivity, confluence templates, share your template

Share Your Confluence Whiteboard Template for a Chance to Be Featured in the Product! 🏆

Want to leave your mark on Confluence? One winner will have their whiteboard design added into Confluence for all users to access! This is your chance to showcase your creativity, help others, and gain recognition in the Confluence community.

Share your template today!
AUG Leaders

Atlassian Community Events