https://confluence.atlassian.com/doc/user-macro-template-syntax-223906130.html
The $body
object is available if you have specified that your macro has a body
Is there a way to determine if the body is empty? I've tried comparing to empty strings or true/false, but it seems that there's always some whitespace there (<p> or <br>).
I'm hoping to toggle some functionality based on if the user enters text in the body or not.
(I'm using the simply velocity context user macros)
If you know exactly what is in the "empty" body, then you can compare it to that? Something like
if ($body=="<p> </p>")
Or more complex using RegEx
If ($body.matches("<p>\s+</p>
"))
I will try something like that. It seems like confluence adds it's own <p> tags within the body by default, even if the user does not.
I guess those tags evaluate as "whitespace" in html. Is there a way to check for any/all combinations of that? remove any whitespace html tags?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, \s is for any white space character. To do some experiments to just print out the $body to see what it actually contains. It may be that $body itself is empty, but the macro instance is being wrapped with p tags when the contents are empty -- HTML wants the content to be wrapped with something.
I did check one of my test macros and found this code, which works in the opposite sense
#set($display="")
## Check if the body exists
#if($body)
#set($display = $body.trim())
#end
If this doesn't help you, please post your macro code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.