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

Linking variables to soy file

Joshua McNeil August 28, 2015

Hi I'm new to working with Soy, and also Stash API, i've been trying to figure out how variable data is passed to a soy file. Particularly from java servlet to soy file. I'm looking at examples such as https://developer.atlassian.com/stash/docs/latest/tutorials-and-examples/decorating-the-user-account.html

In particular the line 

<h3>Hello, {$user.displayName}</h3>

I know that displays the user name but where is that User.displayname information coming from. The java file associated makes no reference to user.displayName. Any suggestions will be appreciated. 

Thanks

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Mibex_Software
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.
August 28, 2015

Hi,

In the example you referred a context is built which is passed to the Soy file:

ImmutableMap.<String, Object>of("user", user)

user is of type StashUser. Objects that are given to the Soy template in this context are exposed according to the Java Beans standard. You can access a method X#getFoo() as x.foo and X#isFoo() as x.foo.

You can therefore just use user.displayName which is using StashUser#getDisplayName()  behind the scenes.

Hope this helps.

Cheers,

Michael

Joshua McNeil August 28, 2015

Thanks, your explanation makes things alot more clear. So i I wanted to get information not only for just the user, but lets say project information as well, can i pass in a project type, as well as the user type?

Mibex_Software
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.
August 28, 2015

Sure. As far as I know, you can use objects of any class you want as long as you provide the necessary getters to access its properties.

Joshua McNeil August 28, 2015

Thanks, will try and let you know the results

TAGS
AUG Leaders

Atlassian Community Events