"Undefined" when trying to use Soy template?

Hey together,

so I’m having some issues implementing my Soy template into my plugin.
The following is present:

plugin.xml

    <web-resource key="library-management-resource-module" name="Wfenhance Library Management resource module">
        <dependency>com.atlassian.auiplugin:ajs</dependency>
        <dependency>com.atlassian.auiplugin:aui-select2</dependency>
        <dependency>com.atlassian.auiplugin:aui-experimental-soy-templates</dependency>
        <transformation extension="soy">
            <transformer key="soyTransformer">
                <functions>com.atlassian.confluence.plugins.soy:soy-core-functions</functions>
            </transformer>
        </transformation>
        <resource type="download" name="responsible-user-search.js" location="/js/responsible-user-search.js"/>
        <resource type="download" name="respusersearch-soy.js" location="/templates/respusersearch.soy"/>
        <context>jira-wfenhance</context>
    </web-resource>

respusersearch.soy

{namespace JIRA.Templates.wfenhance}

{template .userSearch}
<form class="aui" id="kdp-user-select-form">

    <div class="field-group">
        <label for="kdp-user-select">Users</label>
        <div id="kdp-user-select"
                 name="kdp-user-select"
                 class="kdp-aui-select"
                 multiple=""
                 placeholder="start typing a username ...">
        </div>
        <div class="description">The users that should have kitchen duty.</div>
    </div>
    <div class="buttons-container">
        <div class="buttons">
            <input class="button submit" type="submit"
                   id="kdp-user-select-save-button"
                   value="show"/>
        </div>
    </div>

</form>
{/template}

success.vm (view where the template should appear)

<html>
<head>
    <title>$i18n.getText("wfenhance.library-management.title")</title>
    <meta name="decorator" content="atl.admin">
</head>
<body>`Preformatted text`
<h1>$i18n.getText("wfenhance.library-management.headline")</h1>

<div id="kdp-user-select-form"></div>

<p>Here you can manage your present library definitions and import or export them.</p>
</body>
</html>

The js file (responsible-user-search.js)

/**
 * Created by schol on 7/4/2017.
 */
var initUserSearch = function() {

   /* The following line is fine, I can see it has objects. However, my own is missing. */
    var test1 = JIRA.Templates;

    /* Consequently, the following line returns the described error */
    var templateUserSearch = JIRA.Templates.wfenhance.userSearch();

};

AJS.toInit(function(){
    require(['aui/flag'], function(flag) {
        var myFlag = flag({
            type: 'success',
            title: 'JIRA Wfenhance Responsible user search',
            body: 'JIRA Wfenhance Responsible user search controller is working'
        });
    });

    initUserSearch()
})

Someone has an idea where something could be wrong?
I can see that the template doesn’t get found in the Dev Console.
I noticed my namespace seemingly can’t be found.
I don’t think it’s related to my resource as other code from the JavaScript file works (the flag shows up).

Greetings Marcus

Hi Marcus,

Maybe something stupid but can you try removing the leading / in your location path?
Like in the example: https://developer.atlassian.com/jiradev/jira-platform/building-jira-add-ons/jira-plugins2-overview/jira-plugin-module-types/web-resource-plugin-module

Unfortunately no, that doesn’t help.
Something I noted tough:
When looking at the script in the dev console something like this should be given at the start:

;/* module-key = 'com.comsysto.kitchen-duty-plugin:kitchen-duty-plugin-resources--planning-page', location = 'templates-soy/kitchen-duty-planning.soy' */
// This file was automatically generated from kitchen-duty-planning.soy.
// Please don't edit this file by hand.

/**
 * @fileoverview Templates in namespace JIRA.Templates.KDP.
 */

The example above is from a working version according to that tutorial here: Redirecting ...

However, the view I’m having just starts like this:

;/* module-key = 'com.scholledev.jira-wfenhance:library-management-resource-module', location = 'js/responsible-user-search.js' */
var showSuccessFlag = function(a) {
    require(["aui/flag"], function(c) {
        var b = c({

Hi @schollemarcus,

It seems you’re missing SoyDoc in your template. I tested it out using your .soy file and was able to hit an error, although I didn’t get “Undefined”. Kindly add SoyDoc like

/**
* This is user search and a sample SoyDoc
**/
{template .userSearch}

Once I added this in the soy template you provided, it works already.

1 Like

Thanks for your comment and actually you’re right. I was able to sort this out. However there’s one more thing to mention - that got me undefined errors in the end: No blank spaces at the start of the Javadoc lines.

Greetings Marcus

Hi @ianRagudo,

Thank you so much, man!
It works for me as well, saved my life!

My question is, Why does that soy templates needs “Soy-docs” to work?

Thank you again anyway!

:slightly_smiling_face:

You’re welcome, @rafael.moreira. Soy templates or Google Closure templates requires a preceding Javadoc looking SoyDoc comments prior to a template. As to exactly why, I’m not 100% sure where it is being used under the hood, but it’s required as documented AFAIK.

Cheers,
Ian