How to use GeneralUtil in atlassian-plugin.xml

Hello,

I was mimicing the Confluence Space IA plugin to create a space admin button in our template.

the line:

<link id="spacebar-settings-link">/spaces/spacetools.action?key=$generalUtil.urlEncode($helper.spaceKey)</link>

the final render doesn't seem to render correctly, I see the string literal instead of the actual space key.

What am I missing? I didn't see anything obvious in the atlassian-plugin.xml, and I couldn't find a help page outlining the usage.

Thanks!

6 answers

1 accepted

This widget could not be displayed.

So it turned out the $helper is not a accessible by default object.

I ened up with:

<link>/spaces/spacetools.action?key=$generalUtil.urlEncode($space.key)</link>

thanks all for the suggestions.

This widget could not be displayed.

You've put the generalUtil in velocity context?

The best way to do that is bring the $helper.spaceKey already encoded to the velocity template.

with Confluence, GeneralUtil is always in the velocity context. it's one of the default objects.

This widget could not be displayed.

When you say 'I see the string literal' do you mean that you see '$helper.spaceKey' in the output?

This widget could not be displayed.

try

$action.helper.spaceKey

This was close, but it was the $helper object that was null. I ended up using:

<link>/spaces/spacetools.action?key=$generalUtil.urlEncode($space.key)</link>

I guess I saw the helper so much I thought it was there by default.

This widget could not be displayed.

@David Pinn, Yep. But I found my way around it.

This widget could not be displayed.

I discovered that in JIRA, JiraWebActionSupport has method urlEncode, thus I could just do the following in my Velocity template:

$action.urlEncode("my/unsafe/url")

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...

370 views 2 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