Getting started with Templates "Hello world Using Javascript" fails

1,001 views
Skip to first unread message

Ned Imming

unread,
Nov 8, 2011, 3:01:11 PM11/8/11
to Closure Templates Discuss
I'm following along on this page. http://code.google.com/closure/templates/docs/helloworld_js.html
I get to the part where I need to execute this command.
c:\> java -jar SoyToJsSrcCompiler.jar --outputPathFormat simple.js
simple.soy

The output is:

C:\>java -jar SoyToJsSrcCompiler.jar --outputPathFormat simple.js
simple.soy
Exception in thread "main"
com.google.template.soy.base.SoySyntaxException: In file simple.soy:
Not all code is in Soy V
2 syntax (found file simple.soy not in Soy V2 syntax).
at
com.google.template.soy.soytree.SoytreeUtils.createSoySyntaxExceptionWithMetaInfo(Unknown
Source)
at
com.google.template.soy.sharedpasses.AssertSyntaxVersionV2Visitor.visitSoyNode(Unknown
Source)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitSoyFileNode(Unknown
Source)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(Unknown
Source)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(Unknown
Source)
at
com.google.template.soy.basetree.AbstractNodeVisitor.visitChildren(Unknown
Source)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitChildren(Unknown
Source)
at
com.google.template.soy.sharedpasses.AssertSyntaxVersionV2Visitor.visitSoyNode(Unknown
Source)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitSoyFileSetNode(Unknown
Source)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(Unknown
Source)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(Unknown
Source)
at
com.google.template.soy.basetree.AbstractNodeVisitor.exec(Unknown
Source)
at
com.google.template.soy.soyparse.SoyFileSetParser.runCheckingPasses(Unknown
Source)
at
com.google.template.soy.soyparse.SoyFileSetParser.parseWithVersions(Unknown
Source)
at
com.google.template.soy.soyparse.SoyFileSetParser.parse(Unknown
Source)
at
com.google.template.soy.SoyFileSet.compileToJsSrcFiles(Unknown Source)
at com.google.template.soy.SoyToJsSrcCompiler.execMain(Unknown
Source)
at com.google.template.soy.SoyToJsSrcCompiler.main(Unknown
Source)

My simple.soy file looks like:

/**
* Says hello to the world.
*/
{template .helloWorld}
Hello world!
{/template}

I'm using a windows 7 environment if that matters. Though it seems
like the error is telling me that the simple.soy file is not correct
somehow. Any ideas on how I can get started with closure templates?

Juan Mendes

unread,
Nov 8, 2011, 8:21:04 PM11/8/11
to closure-temp...@googlegroups.com
I just added your simple template to my soy file and it worked fine. The problem is not syntax for that template.

This is what I ran

/ccrun/java/3rdparty/j2sdk/bin/java -jar /ccrun/build/SoyToJsSrcCompiler.jar --outputPathFormat client/js/tpl/cci.tpl.js  client/js/tpl/cci.soy


And the output was

cci.common.tpl.helloWorld = function(opt_data, opt_sb) {
  var output = opt_sb || new soy.StringBuilder();
  output.append('Hello world!');
  if (!opt_sb) return output.toString();
};


However, I do have a namespace declaration, which I'm not sure if you do. If I remove mine, I get a meaningful error:

Exception in thread "main" com.google.template.soy.base.SoySyntaxException: In file client/js/tpl/cci.soy: Tag 'namespace' not at start of line.

Try adding the namespace to the top of your file. Also make sure you have a comment for the template, I get the following message when a template doesn't have a comment

In file client/js/tpl/cci.soy, template cci.common.tpl.helloWorld: Not all code is in Soy V2 syntax (missing SoyDoc for template {template .helloWorld}).


Regards,

--Juan
--
Juan Mendes

Mike Samuel

unread,
Nov 9, 2011, 7:26:32 AM11/9/11
to closure-temp...@googlegroups.com
2011/11/8 Ned Imming <nim...@gmail.com>:

I think you need a {namespace foo} declaration at the top of the file.

http://code.google.com/closure/templates/docs/concepts.html#filestructure

Every Soy file should have these components, in this order:
* A namespace declaration.
* One or more template definitions.

Ned Imming

unread,
Nov 9, 2011, 2:29:16 AM11/9/11
to Closure Templates Discuss
I was missing the namespace. I must have skipped that step in the
tutorial document. However, having a meaningful error like Tag
'namespace' not at start of line would be much better than what I got.

Thanks. I'm off and running.

Juan Mendes

unread,
Nov 11, 2011, 3:38:44 PM11/11/11
to closure-temp...@googlegroups.com
My version of closure gives me a meaningful message.  Are you using an old version?
--
Juan Mendes
Reply all
Reply to author
Forward
0 new messages