It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

8 answers

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>

 

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.

Thanks for answer.

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

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

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 ?

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 :-(

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

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 :-( 

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 Gregor Kasmann likes this

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 ?

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

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

 

 

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

 

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

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?

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

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

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?

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

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>

 

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?

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

...
});

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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

6 Awesome Ways to Apply Trello, JIRA and Confluence to your Project

I attended  Atlassian Summit 2019  and learned a lot from the presenters, attendees and knowledgeable Atlassian product managers. The presentations I attended focused on applying Agile, pla...

3,745 views 15 37
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you