Forums

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

How to create a page title using multiple template variables

Marcin Pazdro August 16, 2017

Dear community members,
I'm facing a technical issue which i can't overcome by myself even though I spent some time on it now.

I created a template for some page type. This template request user to specify/choose three variables (let's call them variable1, variable2 and variable3). Once they are specified the page is created. I would like the name of the page to be "Variable1 - variable2 - variable3".

The closest hint on how to do that i found here: https://community.atlassian.com/t5/Confluence-questions/Is-it-possible-de-prefill-a-page-title-based-on-a-template/qaq-p/203821\\
But gives a solution only one variable is used. How to expand it to three variables?

Let say we have a variable in template called "variable2" being a string.
and in user macro we defined a @param pageName:type=string.

How in macro to assign the value of "variable2" to $parampageName in user macro?

Thanks for your support,
Marcin

6 answers

1 vote
jobaker_Sbux
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 27, 2018

I was able to leverage three Variables with the following:

<script>
$( "input[name='variableValues.DateOfIncident']" ).change(function(){
console.log($(this).val());
$("form[name='filltemplateform']").find("input[name='title']").val($(this).val())
})
$( "input[name='variableValues.IRNumber']" ).change(function(){
console.log($(this).val());
$("form[name='filltemplateform']").find("input[name='title']").val($("form[name='filltemplateform']").find("input[name='title']").val() + " : " + $(this).val())
})
$( "input[name='variableValues.IRSummary']" ).change(function(){
console.log($(this).val());
$("form[name='filltemplateform']").find("input[name='title']").val($("form[name='filltemplateform']").find("input[name='title']").val() + " : " + $(this).val())
})
</script>

Adam Niwczinski
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 12, 2018

Hi Jonathan, thanks a lot for your code snippet, it was really helpful!

Do you happen to have an idea, how to extract the selected value of a template variable that is a list (drop-down list with different values)?

I have been struggeling with this for quite a while now, with no success :(

Thanks!

Adam.

Volker Weinreich
Contributor
June 25, 2018

Hi Jonathan, thanks for your code.

You put a colon (":") between the parts. How can I put an underscore ("_") at the beginning of the page title ("_page title"). I don't know the right syntax to put at the top.

Thanks,

Volker

Volker Weinreich
Contributor
February 27, 2019

Found out myself:

 

<script type="text/javascript">

$("input[name='variableValues.Programmname']" ).change(function(){
console.log($(this).val());
$("form[name='filltemplateform']").find("input[name='title']").val("_" + $(this).val())
})
</script>
Rotem Cohen
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 25, 2019

Hi Adam,

I'm having the same problem with select value of a drop-down list template variable .

Did you resolve it after all?

Thanks,

Rotem

Nicky October 8, 2020

Hi, is there a way to do this via the HTML macro because I can't create custom user macro.  I'll need to find a way to add the script in the HTML macro and have that pass the variable to the page title.

Thanks for your help.

0 votes
Priska Aprilia
Contributor
May 15, 2019

Hi Franck,

Where do we need to place this code?

0 votes
Franck Binard February 27, 2019

Hi, you can intercept the form submission event. The form submitted from a template is called "filltemplateform" so for example, in the case where you want to combine two values (ProjectID and projectName to form a page title, just use something like this to your AJS.toInit - I also have a some basic data verification in there, event.preventDefault is to prevent the form submission if the projectID isn't a number between 2 and 5 digits



$("form[name='filltemplateform']").submit(function(event){
let projID = $( "input[name='variableValues.projectID']" ).val();
if (projID.length < 2 || isNaN(projID)){
alert("Invalid value - Project ID must be numerical between 2 and 5 digits");
event.preventDefault();
}
$("form[name='filltemplateform']").find("input[name='title']").val(
projID + " - " + $( "input[name='variableValues.projectName']" ).val());
});
 

 

Priska Aprilia
Contributor
May 15, 2019

Hi Franc,

Where do we need to place this code?

Franck Binard May 15, 2019

You have to put in in an AJS.toInit. It can be done several ways, I used a user macro in which I placed a script tag. Here's a more complete code snippet with validation 


<script>

....

AJS.toInit(function(){


.....

$("form[name='filltemplateform']").submit(function(event){
let projID = $( "input[name='variableValues.projectID']" ).val();
if (projID.length < 2 || isNaN(projID)){
AJS.flag({
type: 'error',
title: 'Invalid Project Number',
body: 'The Project Number is a 2 to 5 digits numerical value '
});
event.preventDefault();
}
$("form[name='filltemplateform']").find("input[name='title']").val(
projID + " - " + $( "input[name='variableValues.projectName']" ).val());
});

$( "input[name='variableValues.projectID']" ).attr("data-aui-notification-field","");
$( "input[name='variableValues.projectID']" ).attr("data-aui-notification-info","Choose a username at least 6 characters long");

$( "input[name='variableValues.projectID']" ).attr("minlength", "2");
$( "input[name='variableValues.projectID']" ).attr("maxlength", "5");

.....


</script>
David Pressley
Contributor
September 21, 2020

How does this work in terms of populating the page title for a page created via the Create Page from Template functionality?

I have it stored in a user macro named filltemplateform.

Now what?

0 votes
EPS Software Engineering AG
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.
April 24, 2018

Hi Marcin,

Maybe the Page Tree Creator could be a solution for you. You can have as many tags (variables) in the title as you like. The tags will be presented in the form during the creation process of the page. For each tag you can define a drop down list.

You can find the Page Tree Creator on the Marketplace and some live examples are here (no registration needed).

Regards,
Stephan (CEO of EPS Software Engineering AG, the vendor of the Page Tree Creator)

0 votes
Casey Schulz April 24, 2018

@Marcin Pazdro were you able to get this to work?

Marcin Pazdro April 24, 2018

Not yet, unfortunately.

Best regards,

Marcin

0 votes
Jesse Katz April 23, 2018

You can use the Create from Template macro to accomplish this.

In the macro you can prefill the page title, as well as choose the template, so I imagine you'll want 3 macros on the page for the 3 title variation.  The macros show up as buttons on the page.

The limitation is that you'll need to go to the page where you embed the macros to create the page, however, you'd probably do this anyway so the page has the correct parent.

https://confluence.atlassian.com/doc/create-from-template-macro-317196995.html

Marcin Pazdro April 24, 2018

Hello Jesse,

Thanks for your hint, but this is still not a solution. These three templates you propose would give me an option to create three different titles. But these titles would always be the same.

What I want to accomplish is to get page title to be composed out of 3 variables which Confluence user can choose by either specifying some variables or selecting them from drop-down list.

So, in what you proposing the number of page title variations would be limited to 3 (plus some variation related to one of the variable which I'm actually able to pass to a title's name).

In what I need, the combination of three variables (which can be specified by customer) would give unlimited number of title options.

Hope this clarifies what I'm looking for.

Best regards,

Marcin

Jesse Katz April 25, 2018

Actually, it may work.  The page title that you put into the macro prefills the Confluence page.  

For example, I've set up a button to say "iOS Release x.x.x"  Before I save the the page, I change x.x.x to 5.1.0, or whatever the version is.

Like Katie Rice likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events