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 <– goog.require(‘goog.string’).
<!DOCTYPE html>
<html>
<head>
<title>codeBox</title>
<script src="{{STATIC_URL}}closure-library/closure/goog/base.js"></script>
<script>
goog.require('goog.string');
</script>
<script src="{{STATIC_URL}}soyutils.js"></script>
</head>
<body>
<script>
console.log(goog.string.trim);
</script>
</body>
(ignore {{STATIC_URL}} that is for Django Server)
console.log(goog.string.trim) will show you “undefined”.
That’s becuase goog.string is overridden by goog.string located in soyutils.js.
how can i get around this problem without compiling ? (when I compile all the files .. then it runs well)
Instead of
use
You can find
soyutils_usegoog.jsin the same directory assoyutils.jsin the closure templates tarball.The problem arises because there are two versions of soyutils.
soyutils.jsis the version for non-closure users and includes just enough closure to make the JavaScript from SoyToJSCompiler work.soyutils_usegoog.jsis the version that works with the closure library and closure compiler. It should not conflict with closure library.Closure Template JavaScript Usage explains: