Is it possible de prefill a page title based on a template variable ?

Raspdealer
Contributor
May 1, 2015

Hey there,

 

I'm trying to define a page title though a template by using variable. Is it a way to do that ?

Something like pagetitle=$myvariable

Thanks a lot

12 answers

5 votes
Raspdealer
Contributor
May 1, 2015

My need is that in my template I created a variable.

I used the template, fill the variable and go on step 2.

 

In this step, I want that the name of my page is prefilled with the variable I've filled on step 1. Is it possible ?

Is it possible to add this variable inside a component in the template ?

Markus Pöhler
Contributor
January 18, 2023

This is basically the same request as the OP has asked. 

His question has been answered, but for me the provided solution does not work.

4 votes
NelsonC
Contributor
May 1, 2015

I dont know if there is a easier way, but you can create a user macro to do  that. I have tested and this works:

## @noparams
<script>

$( "input[name='variableValues.VARIABLENAME']" ).change(function(){
console.log($(this).val());

$("form[name='filltemplateform']").find("input[name='title']").val($(this).val())

})
</script>

 

NelsonC
Contributor
May 1, 2015

Note: $( "input[name='variableValues.VARIABLENAME']" ) --> Replace VARIABLENAME for the name of your variable. I used input for text variable, but you will need to use select for list variable.

Like BlueberryCake likes this
Raspdealer
Contributor
May 1, 2015

Thanks for answer.

But how can I create an user macro if I'm only a space administrator ?

Like simon foley likes this
Nelson Carranza May 1, 2015

Check if you have the html macro and you will only need to include the script ; otherwise, you will need to ask your admin

Raspdealer
Contributor
May 3, 2015

Nope. I need to see with admins. Thanks. If I'll put this script in my template, when I will create a page based on this template, it will automatically copy my variable in the title section when I go on step 2 ?

Michael Curry
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!
December 30, 2015

Is this an option in Confluence Cloud? I can't find it in the General Configuration menu that the Confluence 5.9 documentation talks about -- but that the Confluence Cloud documentation doesn't mention :-(

Lance
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 2, 2016

This works, but I'm trying to have the page title contain other static text.  I can't quite figure out this language.

Basically, I want the title to be something like "IT-DOC - $Application$ Recovery Plan" where $Application$ is the variable that the user enters when creating the page from the template.

Can anyone help with this?

thanks

Like # people like this
Axel Holene
Contributor
June 19, 2017

A bit on the side, but where do you find out about stuff like 

$("input[name='variableValues.VARIABLNAME']")

I am completely lost on making User Macros with the slightest finesse :-( 

Franck Binard February 27, 2019

in google chrome, open dev tools (ctrl-shift-i) then look at the code. You'll be able to find the form and its elements, which gives you their names. 

Like # people like this
2 votes
Jean-Francois Hetu April 16, 2020

I am trying to get this PageTitle to work and just can get around to making it happen. Anybody have a detailed example or step by step?

I have a working user macro which I am able to pull off the variables from. But everytime I create the page from the template, the title always shows empty and I need to manually enter some data into it.

Any help would be greatly appreciated as I've searched left and right for more detailed information.

1 vote
Sukhjit Singh
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!
January 3, 2018

It would be nice to be able to insert custom variables in the title parameter of the Create from Template Macro.  Anyone have any ideas when this will be possible?

0 votes
Andy Moore
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 30, 2021

following the solutions given previously, I have created my own variation that takes multiple fields from my template to create the page title:

<script>
var partnum,majver,minver,prodname;
$("input[name='variableValues.prodname' ]").change(function() {

partnum=$("input[name='variableValues.partno']").val();
majver=$("input[name='variableValues.majver']").val();
minver=$("input[name='variableValues.minver']").val(); 
prodname=$("input[name='variableValues.prodname']").val();

console.log(partnum+majver+minver+prodname);


  $("form[name='filltemplateform']").find("input[name='title']").val(partnum+"."+majver+"."+minver+"."+prodname)
})


</script>
Andy Moore
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 30, 2021

note that the macro is triggered when 'prodname' gets entered, so it has to be the last field that the user is likely to enter otherwise the earlier fields will be empty.

Victor Sluiter
Contributor
April 30, 2021

Hi Andy,

Did you make this for server or for cloud?

Jide Akinyode
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!
May 8, 2022

Hi Andy,

So I've got this working, but I had a few questions. 

I had to add the variables to the template. Since this information is captured in the page title, I DO NOT want to display is again. How can this be hidden?

0 votes
Dominic Lagger
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 16, 2020

Hi all

There would be a really easy workaround for this. 

Confluence Server

You can add the "Create from Template" macro on any page. There you can choose the template and the template name. No if you click the button, it will generate a subpage with the template and your template name.

Confluence Cloud

It's the same as server. Here's the Cloud documentation for "Create from Template".

The downside is, you can't create the page from the navigation. You have to go the page and click the button. 

Regards, Dominic

Victor Sluiter
Contributor
August 14, 2020

Hello Dominic,
I'm visiting this page because that doesn't work. Of course you can "create from template". The problem is that I'd like to have the users add variables and thereby create the page name. In our case, "logbook_WPx_subject". I'd like the users to fill in the x, and the subject, and then the page will be created with the title. For instance, fill in 2 for x, and "understanding confluence" for subject, and I'd like to get a page "logbook_WP2_understanding confluence". 
Is this possible in Cloud? I was not able to do it:

variable.gif

Like # people like this
evanbartlett
Contributor
February 4, 2021

I have the same question, the "Create from template" only seems work for one variable out of a list of 3 pre-defined variables. 

Like Florian likes this
0 votes
Jorge_Reyes
Contributor
April 16, 2020

I'm an space admin. There have been a lot of changes. Can I still do this?

Jean-Francois Hetu April 16, 2020

I guess this question has the merite to get answered. I've been trying without success... perhaps this feature is no longer available?

0 votes
Deleted user June 5, 2019

Not a complete solution, but if you use the Create Template macro there is a field in the dialog for "Title of page to be created"

You can't use template variables (that I know of), but at least you can give the person creating the page a hint as to what name you should be using.

0 votes
Franck Binard February 27, 2019

This code below can be added to a user macro to combine a template variable projectID with another template variable projectName to form a page title. Just intercept the submit event for the filltemplateform. I added some basic data verification to ensure projID is a number between 2 and 5 digits. 

AJS.toInit(function(){


$("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());
});

...
});
0 votes
Ingo Kampe
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!
July 29, 2016

It's an old topic but I still can not find a solution for it in Confluence 5.10.

As Raspdealer has written I would like to achieve the same two simple(?) things:

  • use variable values of templates in the pagetitle
  • use variable values of templates in macros

Anybody has accomplished that somehow?

Thanks

 

Jennifer Phelan
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!
July 18, 2017

1. Create a user macro that accepts a parameter. I slightly modified the code Nelson provided.

2. Add a variable to the template page (use IE and not Chrome). $Meeting Date

3. Add a section to the template page, type in the following and then press Enter: {mtg-date-page:pageName = Weekly Status Meeting}

User Macro Code: 

## @param pageName=Page Name|type=string|desc=This is the general name of the page. It will be appended to the date value which is stored in the Meeting Date variable on the page template.
<script>
var pageTitle= "$parampageName";

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

 

 

 

 

 

 

 

Like Volker Weinreich likes this
Ian Underwood July 28, 2017

That works great for one variable in a template, but what if I want to set the page title based upon two variables in a template?

Marcin Pazdro August 15, 2017

Hello Ian,

Did you find a solution for your issue?

I'm struggling with slightly similar challagne. I would like my template to be creating a pages with a name composed out of three variables. and I still haven't figured out how to do that.

Best regards,

Marcin

Marcin Pazdro August 15, 2017

Hello,

Another question to community.

Let say that a template request a variable called "$variable1" beeing a string. How to define in a macro a parameter/variable "$variable2" having the same value as "$variable1" from the template?

Sorry if this is a stupid question. I'm not programmer.

Thanks and regards,

Marcin

Casey Schulz April 24, 2018

I've created the user macro and added it to the top of my template page but it's not creating the title automatically. I'm using the "create from template" button on the main page to call the template that has the macro on it.

What Body processing option should be chosen?

Any suggestions?

Volker Weinreich
Contributor
November 14, 2018

Hi,

why does this work:

$("form[name='filltemplateform']").find("input[name='title']").val($(this).val() + " " + pageTitle)

but the following does not?

$(pageTitle + " " + "form[name='filltemplateform']").find("input[name='title']").val($(this).val())

What do i have to do to put the pageTitle in front?

Or how can I set an underscore ("_") at the beginning?

Thanks.

Volker

Volker Weinreich
Contributor
November 15, 2018

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>

 

Nicky October 8, 2020

Can someone help explain how to do this using an HTML macro? I can't create a user macro so I have to add this script in the HTML macro but that doesn't seem to pass the variable to the title. 

Thanks. 

Like evanbartlett likes this
evanbartlett
Contributor
February 4, 2021

I've got the same question as Nicky

Like Nicky likes this
Nicky February 4, 2021

Actually, I got it working in the HTML macro using the following:

<script type="text/javascript"> 

AJS.toInit(function() {

AJS.$("input[name='variableValues.VARIABLENAME']" ).change(function(){
console.log($(this).val());
AJS.$("form[name='filltemplateform']").find("input[name='title']").val($(this).val()) })

});

</script>
Like evanbartlett likes this
evanbartlett
Contributor
February 4, 2021

Thanks! I'm completely new to the HTML macro.  Could you give me any direction on how to look into setting it up?

Basically I'm using a section in confluence for meeting notes, and everyone on the team is confused by why they can't create notes with the same name.  I'd like them to click to create a page, and for that title to be pre filled with some information for them that would make it unique.  

Nicky February 4, 2021

To be honest, I’m not sure how this would would in your use case.

For me, I am using this with a custom created template.  In that template, I use custom variables, and this script passes that variable to the page title in step 2 of the template creation process. So, my template page uses one variable in 3 places on the page where I’d like the same content displayed, and I also want this to be the name of the page.

I would say in your case, maybe create a “meeting notes” template.  In your confluence space, go to space tools (bottom left) > content tools > create new template.

In your template, add variables as needed and use the above script (in an HTML macro) to pass the that variable to the page title. 

Then, use the “create from template” macro to add a button somewhere that your users can use to create a new meeting notes page from your template.

Markus Pöhler
Contributor
January 18, 2023

Nicky's approach with HTML makro does work, using Confluence 7.13 DC.

0 votes
Raspdealer
Contributor
May 3, 2015

And is it possible to add this variable in a component ? For example a JIRA Macro ?

 

 

0 votes
Nelson Carranza May 1, 2015

Hi,

You can use the add-page-form macro from Linking Plugin. It is a free plugin. 

https://marketplace.atlassian.com/plugins/net.customware.confluence.plugin.linking

 

Regards

Nelson

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events