Macro default values not being passed

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

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

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.

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

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>

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Confluence

Three common content challenges + how to manage them

An efficient enterprise content management system, or ECM, is a must-have for companies that create work online (cough   cough, all companies). If content calendars, marketing plans, and bu...

73 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you