Reputation: 58786
Is it possible to use Google Closure Templates with Clojurescript?
I have looked around but haven't found any information regarding this.
Upvotes: 4
Views: 699
Reputation: 2727
As the Soy Templates are compiled down to JavaScript functions, you should be able to use it without any problem. Look here for a general explanation of how to use external JavaScript libraries in ClojureScript:
http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html
You should also compile your templates with this flag: --shouldProvideRequireSoyNamespaces
, look here for more information.
As another option you could use a templating library written for ClojureScript. There are at least two great libraries: Dommy and Enfocus.
Upvotes: 2
Reputation: 379
The Google Closure templates should work in ClojureScript without much hassle. Try referencing the goog.whatever namespace at the top of your ClojureScript file like normal. If you're not using advanced mode compilation, then reference your cljs file's namespace with a goog.require in the HTML page. Otherwise, you don't need goog.require when compiling in advanced mode.
So if you have a project named foo, a ClojureScript file named bar, and you want to use goog.dom without advanced mode, you could try something like this:
cljs file
(ns foo.bar
(:require [goog.dom :as dom]))
in the index.html
<script type="text/javascript" src="js/compiled.js"></script>
<script type="text/javascript">
goog.require('foo.bar');
</script>
The twitterbuzz sample gives a good example of this.
Upvotes: 1