user macro different result using $helper.renderconfluencemacro directly and after storing in a variable
Asked by Jonathan Simonoff:

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?


Answers:
author: Jonathan Simonoff
body: 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.


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

comments: author: Jonathan Simonoff
body: That is the shorthand notation ([](https://velocity.apache.org/engine/devel/user-guide.html#variables)<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.


author: Davin Studer
body: 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.


author: Davin Studer
body: 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?


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


author: Remo Siegwart
body: 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

comments: author: Jonathan Simonoff
body: 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.


Tags: confluence-administration

user-macro