Skip to content Skip to sidebar Skip to footer

Goog.string Is Overridden When I Use Soyutils.js

goog.string is not able to be used when soyutils.js is included in the same HTML file. because in soyutils.js has its own goog.string that completely override goog.string <-- go

Solution 1:

Instead of

<script src="{{STATIC_URL}}soyutils.js"></script>

use

<script src="{{STATIC_URL}}soyutils_usegoog.js"></script>

You can find soyutils_usegoog.js in the same directory as soyutils.js in the closure templates tarball.

The problem arises because there are two versions of soyutils.

  1. soyutils.js is the version for non-closure users and includes just enough closure to make the JavaScript from SoyToJSCompiler work.
  2. soyutils_usegoog.js is the version that works with the closure library and closure compiler. It should not conflict with closure library.

Closure Template JavaScript Usage explains:

JavaScript code that's generated by the template compiler depends on a number of utilities.

Include one of these two utility files, depending on whether you're already using the Closure Library:

  • javascript/soyutils.js
  • javascript/soyutils_usegoog.js

These files are included in the tarball you can download from the Closure Templates downloads page.

If your project already uses the Closure Library, use soyutils_usegoog.js, which is a much smaller file than soyutils.js.


Solution 2:

Also just want to add to above answer if you are using google closure library then you might need to add

base.js

then

goog.require('goog.string.StringBuffer');
goog.require('goog.soy.data');

then

soyutils_usegoog.js


Post a Comment for "Goog.string Is Overridden When I Use Soyutils.js"