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

Having trouble referencing soy template

N March 23, 2017

Hello everyone

I'm trying to reference a template in .soy template file called 'JIRA.Templates.Test' from  JS file.

I'm getting the error: Uncaught TypeError:

Cannot read property 'helloWorld' of undefined at q.render

Can you help me?

<web-resource key="my-resources" name="my-web-resources">
     <dependency>com.atlassian.auiplugin:ajs</dependency>
      <dependency>com.atlassian.auiplugin:dialog2</dependency>
      <dependency>com.atlassian.auiplugin:aui-experimental-restfultable</dependency>
      <dependency>com.atlassian.auiplugin:aui-experimental-soy-templates</dependency>
       
    <resource type="download" name="view-tests.js" location="/test/view-tests.js"/>
      <resource type="download" name="edit-test-row.js" location="/test/edit-test-row.js"/>    
      <resource type="download" name="test-row.js" location="/test/test-row.js"/>
    
       <resource type="download" name="view-tests.vm" location="/test/view-tests.vm"/>
      <resource type="download" name="view-test-days.vm" location="/test/view-test-days.vm"/>    
      <context>my-resources</context>
      <transformation extension="soy">
          <transformer key="soyTransformer"/>
      </transformation>
        <resource type="download" name="templates.soy.js" location="/templates/templates.soy"/>
      <transformation extension="js">
            <transformer key="jsI18n"/>
        </transformation>
</web-resource>
{namespace JIRA.Templates.Test}
{template .helloWorld}
<div>Hello !</div>
{/template}
jQuery(function () {
     AJS.$('#edit-tests').click(function() {   
         
          
        var template = JIRA.Templates.Test.helloWorld();
        
        
    }); 
})

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Volodymyr Krupach
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.
March 24, 2017

Hi Natalia,
I did not use SOY for a while and I can not tell you what is wrong with your sample but here is snippet from my old project:

{namespace Confluence.Templates.SomeName}

{template .someFunction}
{/template}

and in JS I have:

"use strict";
define('_myEntryName', [ 'jquery', 'confluence/templates'], function($, Templates) {
  ...
  Templates.SomeName.someFunction();
  ...
});

Maybe reason is that JS compiled from the SOY templates does not declare global JS variable but AMD entry so it should be referred as in the code block above. Anyway I remember that I had to look into Confluence/JIRA sources to make it work.

TAGS
AUG Leaders

Atlassian Community Events