Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Getting a Soy function to work in a Stash plugin

David Pinn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 20, 2012

Hey there, guys. Which ducks do I need to get in a row to make a Soy function work in a Stash plugin? Here's what I have so far:

  • soy-template-renderer-api added as a dependency in the POM
  • soy-template-plugin added as a dependency in the POM. Is this needed?
  • soy-function defined in atlassian-plugin.xml
  • Function class defined, implementing SoyServerFunction and SoyClientFunction
  • Function referenced in Soy template as {nav_test}

I can see that the Soy function's constructor is called during plugin start-up, but none of the other methods. The atlassian-stash.log shows this when I refresh the page containing the function call:

com.google.template.soy.base.SoySyntaxException: In file file:/blahblah/mytemplate.soy:25: Unrecognized function 'nav_test' (function call "nav_test()").

It seems that the function isn't getting registered properly. What have I missed?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

5 votes
Answer accepted
seb
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 24, 2012

Hey Dave - sorry for the late reply.

You should have it bang on. Here is what you will need to export a soy function in a plugin. Let me know if you are still having trouble

1. pom.xml depends on stash-template-renderer-api

<dependency>
    <groupId>com.atlassian.soy</groupId>
    <artifactId>soy-template-renderer-api</artifactId>
    <version>1.1.7</version>
</dependency>

2. Define your function in your atlassian-plugin.xml

<soy-function key="name-of-soy-function" class="com.my.plugin.MyNavFunction"/>

3. Implement com.my.plugin.MyNavFunction extends SoyServerFunction<String>

4. Reference your function as you defined getName() in your implementation.

From what I can tell, you haven't actually missed anything. Are you calling it from a web panel served from your plugin, or are you rendering a servlet which is decorated by Stash?

David Pinn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2012

Thanks Seb. I understand that you might be busy at the moment.

I'm calling the function from a template that is being rendered directly from a servlet. I've got around the problem by simply injecting the URL (which I had wanted the function to return) into the template as model data. Just wondered why it didn't seem to work for me. Not to worry; my work-around is adequate.

0 votes
Jens Schumacher [Atlassian]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2012

David, feel free to get in touch directly if you need anything from me or if you have any questions.

TAGS
AUG Leaders

Atlassian Community Events