user macro different result using $helper.renderconfluencemacro directly and after storing in a variable

Take a page containing an attachments macro.

Include it into another page using a user macro that writes the include as wiki markup and executes $helper.renderconfluencemacro

That works fine.

In the user macro, now store the result of $helper.renderconfluencemacro in a velocity variable, and print that, like this:

#set($macro="{include: ${paramName} }")
#set($page=$helper.renderConfluenceMacro($macro))
$page

The resulting page is now screwed up -- something happens in the middle of the attachments macro's output, and the rest of the page doesn't show.

I've examined the results with the Chrome debugger, and I don't see what is wrong. I didn't see any related errors in the console.

Anyone have an idea what is happening?

3 answers

1 accepted

This widget could not be displayed.

I was able to determine that a lot (though not all) of the problems are due to an iframe put in by the attachments macro. (As discovered by Davin, my problem only happens when drag-and-drop is turned on for tha macro). The offending line is:

<iframe class="plugin_attachments_uploadiframe hidden" name="haZWwwvlQLusX3zF97FMhgclmFMl4K5NcJrP6wljX5WaAYtE9qiZtY6pN7plcSHd" src="" />

If I remove this line from the included contents before printing, things go better. The display of this macro is still somewhat messed up, but the rest of the page prints.
This widget could not be displayed.

Hi Jonathan,

I think you need to use $action.helper.renderConfluenceMacro(...) in user macros. The following works for me:

## @noparams

#set($macro="{cheese}")
#set($page=$action.helper.renderConfluenceMacro($macro))
$page

Hope this helps.

Cheers
Remo

I guess I wasn't clear enough -- I'm not having a problem running renderConfluenceMacro ($helper in my sample was set to $action.helper, I just didn't include that detail). As I mentioned, my code works fine as long as I print the output of the render directly, without first storing it in a velocity variable.

The problem is that I get a display failure if I store it in a variable and then print it.

You may be confused because I didn't say why I'd want to do that -- I left out that detail to simplify the problem. If you want to understand that, I want to manipulate the result before printing it. In testing why that wasn't working, I discovered that just storing in a variable was enough to screw up the output.

This widget could not be displayed.
Davin Studer Community Champion Feb 16, 2014

I don't think this part (${paramName}) is right. The $ should be next to the variable name.

That is the shorthand notation (https://velocity.apache.org/engine/devel/user-guide.html#variables). The form with braces is for situations where the interpreter might get confused.

I think I said this, but: the code I gave works fine, except when the included page includes an "attachments" macro AND I store the result in a velicity variable before printing it. In that case only, the result is screwed up. When I saw "screwed up" I don't mean that it prints the velocity variable, I mean that there's something fairly subtle wrong with the output, so nothing past the attachments macro gets printed, including the page footer.

Davin Studer Community Champion Feb 16, 2014

Ok ... sorry I misread the question. Also, I didn't realize that was velocity syntax ... never had a reason to have the curly braces in it.

Davin Studer Community Champion Feb 16, 2014

I've tried replicating your issue with a user macro. I was able to get pages to include if there was an attachments macro on that page correctly only if the upload option was turned off for the attachments macro. If upload is turned on then it messed up. Is this the same issue you are having?

Yes. I hadn't tried that -- turning off download in attachments does allow this to work. That is helpful, thanks.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

399 views 4 6
Join discussion

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