Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Macro default values not being passed

Stuart Bennett December 12, 2011

It appears that when using the user macro browser, default parameter values are not being passed to the user macro.

For example, when using the following:

## @param locations:title=Locations|type=string|required=false|default=all|desc=The locations to report on.

If the parameter value is left as the default all by the user, an empty/null value is passed to the user macro instead of the expected all.

4 answers

2 votes
CharlesH
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.
May 9, 2012

This is an issue in Confluence 4.2 as well.

As a workaround, you can check each parameter for a null value using Velocity, and in that case apply your chosen defaults. From an end-user perspective things work as they should like this.

Example:

##Check default values (bug in Confluence - https://jira.atlassian.com/browse/CONF-23704)
#if(!$paramoddcolor)
#set($paramoddcolor = "ffffff")
#end
#if(!$paramevencolor)
#set($paramevencolor = "ededed")
#end

childnode October 16, 2013

still in 5.2 :(

1 vote
Andrew Frayling
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.
December 14, 2011

Hi Stuart,

I think you're hitting this reported bug https://jira.atlassian.com/browse/CONF-23704

I'm seeing the same behaviour as well, but have observed that if the value a user provides is the same as the default value then the value is not passed to the macro. If the user provides anything that is different to the default value then the user provided value is passed to the macro.

0 votes
Stuart Bennett December 14, 2011

Just to add to this, an example of a macro that shows this problem is:

## @param myname:title=myname|type=string|desc=descy|required=true|default=MY DEFAULT VALUE

  <div id="$parammyname">
  $parammyname
  </div>

0 votes
Stuart Bennett December 12, 2011

Atlassian didn't understand my problem here, so this may help to explain it:


The problem occurs when creating and using a User Macro. At the top of the macro code I define a parameter in the following way:

## @param locations:title=Locations|type=string|required=false|default=all|desc=The locations to report on.

The User Macro browser then understands that this particular macro can accept a parameter called "locations". As I have set a default value of "all" in the line shown above, the User Macro browser shows that "all" value by default in the field for that parameter. The problem occurs at this point if the user decides to go with the default value of "all" for this parameter. I am finding that in that case, the "location" parameter's default value of "all" is not being passed to the User Macro code. The value of the "location" parameter is only passed to the User Macro code if the user decides not to use the default value and gives their own value instead.

If predefined default values are not being sent to the User Macro code then what is the purpose of setting them?

Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events