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

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.

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.

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

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.

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

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
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
Posted Tuesday in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

485 views 19 10
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