Questions tagged [google-closure-templates]

Closure Templates are a client- and server-side templating system that helps you dynamically build reusable HTML and UI elements

Closure Templates are a client- and server-side templating system that helps you dynamically build reusable HTML and UI elements. They have a simple syntax that is natural for programmers, and you can customize them to fit your application's needs. In contrast to traditional templating systems, in which you must create one monolithic template per page, you can think of Closure Templates as small components that you compose to form your user interface. You can also use the built-in message support to easily localize your applications.

Closure Templates are implemented for both JavaScript and Java, so that you can use the same templates on both the server and client side. They use a data model and expression syntax that work for either language. For the client side, Closure Templates are precompiled into efficient JavaScript.

What are the benefits of using Closure Templates?

  • Convenience. Closure Templates provide an easy way to build pieces of HTML for your application's UI and help you separate application logic from display.
  • Language-neutral. Closure Templates work with JavaScript or Java. You can write one template and share it between your client- and server-side code.
  • Client-side speed. Closure Templates are compiled to efficient JavaScript functions for maximum client-side performance.
  • Easy to read. You can clearly see the structure of the output HTML from the structure of the template code. Messages for translation are inline for extra readability.
  • Designed for programmers. Templates are simply functions that can call each other. The syntax includes constructs familiar to programmers. You can put multiple templates in one source file.
  • A tool, not a framework. Works well in any web application environment in conjunction with any libraries, frameworks, or other tools.
  • Battle-tested. Closure Templates are used extensively in some of the largest web applications in the world, including Gmail, Google Docs, and Google Shopping.

Source:- https://developers.google.com/closure/templates/

76 questions
21
votes
3 answers

Templating system for both Python and Javascript?

A nice feature of Google's Soy templates is that you can use the same templates on the client (JS) and on the server (Java). Currently I plan to render most pages client-side using Soy templates compiled to JS. However, my backend is written in…
nickbaum
  • 583
  • 4
  • 11
10
votes
1 answer

How to declare local variable in closure javascript template

I started learning closure javascript template library . Is it possible to create local variable inside a closure template soy file ? I tried using $i=1; but it prints $i=1 on screen in place of declaring it. I had looked inside examples at…
Vivek Goel
  • 22,942
  • 29
  • 114
  • 186
10
votes
3 answers

How can live without inheritance in closure templates in big project?

We use closure library and closure compiler, and we want to use closure templates. But closure templates haven't got inheritance. That's really a problem for us. As I understand, the reason why closure templates don't have inheritance, is because…
10
votes
1 answer

Read file with fs.readFileSync and eval contents...which scope have the functions? How to access?

I recently tried to import a file into my existing node.js project. I know this should be written with a module but i include my external javascript file like this: eval(fs.readFileSync('public/templates/simple.js')+'') The contents of simple.js…
Johnnycube
  • 1,060
  • 1
  • 10
  • 25
9
votes
2 answers

Why am I missing soyDocs for my soy template?

Plovr is raises a compile-time exception when I try to compile this soy template. // Copyright 2012 David Faux /** * @overview Lays out the home page. */ {namespace templates.home} /* * Lays out the home page. */ {template .main}

Hi!…

dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206
7
votes
1 answer

How to enable spellchecking for custom language plugins in IDEA?

IntelliJ spellchecking appears to be disabled for certain custom language plugins such as Markdown (extension ".md") and the Non-Dairy Soy Plugin (extension ".soy") even with the Spelling | Typo inspection options enabled: Process Code Process…
6
votes
1 answer

Passing Java object into closure template?

As far as I know, Google Closure Template doesn't allow passing Java object into the template (as compared to FreeMarker). So I can't really do something like: // Java file class Course { ... public function getName() { return name; …
huy
  • 4,782
  • 6
  • 36
  • 42
5
votes
2 answers

Pre-compiled Closure Templates - "Variable referenced before declaration" Warning in Closure Compiler

java -jar SoyToJsSrcCompiler.jar --shouldGenerateJsdoc --outputPathFormat simple.js --srcs simple.soy SoyToJsSrcCompiler generates a js file which looks like this: if (typeof templates == 'undefined') { var templates = {}; } if (typeof…
sanchez
  • 4,519
  • 3
  • 23
  • 53
5
votes
1 answer

Logical operators in Closure Templates

I'm playing with Google Closure Templates and I'm unable to successfully compile some templates because it seems that the logical "and" and "or" operators can't be used inside the if tag (I tried both "&&" and "and" and "||" and "or")... how can I…
daveoncode
  • 18,900
  • 15
  • 104
  • 159
4
votes
1 answer

Why is there no space after "Hello" in my Closure template?

I am trying to teach myself Closure templates. I made a simple file simply.soy: {namespace examples.simple} /** * says hello to the world * @param? name Optional parameter specifying who you are greeting. */ {template .hiWorld} Hello {if…
dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206
3
votes
2 answers

Nesting closure templates within another template

I'm sure there should be some way to render another template from within a template so I don't have to copy paste similar looking blocks. I'm just not able to figure it out.
IsmailS
  • 10,797
  • 21
  • 82
  • 134
3
votes
2 answers

Is it possible to create objects within Closure templates?

I've just started doing some work with Google Closure, and I'd like to move the creation of select fields into its own template, and call into that template with something like: {call templates.utils.select} {param name: 'state'/} {param value:…
Cebjyre
  • 6,552
  • 3
  • 32
  • 57
3
votes
1 answer

How to declare and update variables in google closure templates(soy template)

Lets take 2 arrays arr1 = ['a', 'b', 'c'] and arr2 = ['1' , '2', '3']. When passed these arrays as params to a soy template, I want to iterate as shown below and print an index that indicates total items iterated so far. index: 0 //variable assigned…
Srikanth
  • 471
  • 2
  • 14
3
votes
1 answer

How to check for an empty Map in a Soy template?

I've read the docs for Google Soy/Closure templates, but can't find any way to check whether a Map is empty; I can only look up the map's value for a given key. Is there a way to find out the size of a Map? My current workaround is to replace any…
Andrew Swan
  • 13,427
  • 22
  • 69
  • 98
3
votes
2 answers

How to do localization in Google Closure

Currently I am using just plain text in my Closure application. I want to add localizations to those text. I just found several articles about goog.getMsg function which is used to do this kind of localization. As far as I understood it is done in…
1
2 3 4 5 6