13 Replies Latest reply on Mar 19, 2014 12:54 PM by pradeepgm

    Porting old freemarker code to soy?




      I'm quite new to freemarker and closure templates, and I'm currently looking to migrating to version 6 a Jive instance on which many UI modifications were made in the freemarker templates, and face cases like the following. In some cases, some freemarker templates in v6 have been replaced by closure (soy) templates: are the cases below as easily resolved, or possible at all using a similar logic with soy templates?


      Freemarker Example 1:

      ${JiveGlobals.getJiveProperty("site.jumpnav2.url", "/community/suppliers")}


      Freemarker Example 2:

      <#assign userLocale = 'en'/>

                          <#if  action.getRequest()?? && user?? >

                              <#assign userLocale = statics['com.jivesoftware.util.LocaleUtils'].getUserLocale(action.getRequest(), user)/>


                          <#if userLocale?contains('fr')>







      Any thoughts? Ideas?


      Thanks for your help!

        • Re: Porting old freemarker code to soy?

          Would it be possible to elevate the discussion a bit around what you are trying to do with the extensions? One of the reasons we moved to the app framework, including adding things like app actions, is to try and avoid the low level customizations that you are trying to do. Rather than simply port everything over, I'd like to see if there's an alternate way of approaching the problems/limitations that led you down the path of building the templates in the first place.

            • Re: Porting old freemarker code to soy?

              Hi Mark,


              these ftl markup examples were used to generate things such as an additional, custom navigation menu in the header. For example, as our community is used in both English and French, the locale (i.e.: is the interface in English or French?) was first detected in order to in some instances generate slightly different markup, and also to specify texts and urls which values could be overridden through system settings key, should the need arise.


              I'm looking forward to suggestions about how to accomplish this!

            • Re: Porting old freemarker code to soy?

              Anyone with experience in freemarker and closure (soy) templates reading this? Or knowing someone experienced with it in implementing Jive solutions that could be willing to share their knowledge with the community?



                • Re: Porting old freemarker code to soy?

                  Stewart Wachs, anyone from PS might have a few ideas for Julien Renaud??

                  • Re: Porting old freemarker code to soy?

                    Soy is more restrictive than Freemarker - it can only reference parameters that are specifically passed to the template.  That means that references to statics, action, and the like are not allowed in soy.


                    Your options for working around this depend on whether your customizations come from a theme or a plugin.   With a plugin you may be able to extend the bean produced by each action with the parameters that your template needs.  Or in some cases it is possible to write a soy plugin (documentation) to access resources such as jive properties.


                    In some cases people have opted to switch to using JavaScript since you get more flexibility there.  There are some global variables available in the browser in 6.0; here is a list with example values:


                    _jive_base_url          = ""
                    _jive_base_absolute_url = "https://community.jivesoftware.com"
                    _jive_resource_url      = "/5.0.2"
                    _jive_theme_url         = "/themes/"
                    _jive_current_user      = {
                        anonymous:   true|false,
                        partner:     true|false,
                        visible:     true|false,
                        username:    "jesse.hallett",
                        ID:          "2819",
                        enabled:     true|false,
                        avatarID:    "4087",
                        displayName: "Jesse Hallett"
                    _jive_effective_user_id = "2819"
                    _jive_auth_token        = "83afe22"
                    _jive_locale            = "en_US"
                    _jive_timezoneoffset    = -8
                    jive.global.containerType = "14"
                    jive.global.containerID   = "1"
                  • Re: Porting old freemarker code to soy?


                    I just found this guide that talks about Soy templates in Jive 5 or 6:
                    Guide to using Google Closure Templates in Jive 5.0 / 6.0


                    I had a really hard time trying to find it. Has anyone come across some document explaining how SoyModelDrivenActions work?



                    • Re: Porting old freemarker code to soy?

                      Thank you Jesse, Is there a reference page for all inbuilt Javascript variables?

                        • Re: Re: Porting old freemarker code to soy?

                          As far as I know there is no better documentation than my comment above.  I can tell you that our convention is to use global variables prefixed with "_jive" or properties on the jive.global object.  Inspecting a live community with javascript debugging tools is a reliable way to see what is available.


                          The Webkit debugging tools, which are built into Chrome and Safari, have an autocomplete feature in the Console tab.  You can type "_jive", press tab, and see a list of the available variables.  Or you can enumerate global variables in any browser with this code snippet:


                          Object.keys(window).filter(function(key) {
                              return /^_jive/.exec(key);


                          Properties that have been available more recently tend to appear in the jive.global object, which can also be inspected with debugging tools.