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
1
vote
1 answer

How can I create my own custom functions for Closure templates in Plovr

I'm using Plovr and would like to use my own custom function (specifically a ucfirst function) inside templates. At the moment I'm only interested in rendering the templates as javascript, and since this is a fairly simple case I think actually…
Cebjyre
  • 6,552
  • 3
  • 32
  • 57
1
vote
1 answer

Is it possible to concatenate two strings in soy (Closure Templates)?

With soy, I would like to concatenate two strings (hard-coded or variables) into one. My idea was to "parametrize" the first variable with the second: {let $key: 'abc_$anothervariable' /} This doesn't work. I also tried using builtin join() function…
magnes
  • 139
  • 1
  • 2
  • 11
1
vote
2 answers

Does plovr support the latest closure library?

I was using plovr as closure compiler for the latest google closure library, but it think it plays nicely. Why is this so? Link=http://plovr.com/docs.html Thanks in advance for the help, Kiran
1
vote
1 answer

How can I pass a list of html element as parameter into a Closure template

My template is this one below, and I'd like to use a list of html as parameter {template .myTemplate} {@param title: string} {@param? listHtml: list}
    {foreach $item in $listHtml}
  • {$item}
Donovant
  • 3,091
  • 8
  • 40
  • 68
1
vote
1 answer

How can I render a tr with soy templates?

I've got this soy template {template .myRowTemplate} Hello {/template} and I want to do something like var myTable = goog.dom.createElement("table"); goog.dom.appendChild(myTable,…
Dave Aaron Smith
  • 4,517
  • 32
  • 37
1
vote
1 answer

How to convert efficiently a Java object to SoyData in Google Closure

We have a Java object with data that we want to use for template rendering - is there an efficient way of converting Java object to SoyData? Currently we are using gson to convert it to tree and recursively populate SoyData object, but maybe there…
alobodzk
  • 1,284
  • 2
  • 15
  • 27
1
vote
0 answers

Compile Google Closure templates using Maven

I am developing Java Spring MVC application built upon Maven and I would like to compile SOY templates stored within the 'resources/soy' directory to JavaScript files that could be accessed via presentation tier. This could be done manually using…
Sezi
  • 73
  • 8
1
vote
0 answers

goog.ui.ToolbarMenuButton is not a function ; Google Closure

Hey I am trying to add a toolbarMenuButton to my toolbar but for some reason I get this error goog.ui.ToolbarMenuButton is not a function ; The toolbar is going to be a mix of toolbarButton and toolbarMenuButton. Right now its just…
1
vote
1 answer

Closure Templates: setting global variable from passed paramater in soy file

is there a way to set global variables in the .soy file to parameters passed in from .html? So that all templates would be able to access the global variables to avoid the redundancy of repassing the same parameters to each template. For example…
Emil A
  • 55
  • 7
1
vote
0 answers

Google Closure Template: how to create a plugin which prints HTML?

I am trying to write a plugin for Templates which gives me the ability to write a predefined set of HTML and JS inside a {template}. Unfortunately it seems that there is no way to tell the compiler not to compile a JsExpr without using…
Claudio
  • 5,740
  • 5
  • 33
  • 40
1
vote
2 answers

Closure template - if condition string contains

I would like to write an if condition and check if a variable contains a certain string and then write some logic. if i have a variable say @param activity How can I check that variable activity contains the string "abc"?
user1983
  • 21
  • 2
  • 7
1
vote
2 answers

Closure library component + Closure templates

When you add a Closure Component as a child of other component, they should be parent and son in the DOM also. This is actually a pretty useful constraint. The thing is I have some complex Closure Components and it'd be preferrable to create their…
1
vote
1 answer

how to properly call google closure strContains

When I try to compile soy template containing this closure code {if strContains($field, "date") } This is the error com.google.template.soy.base.SoySyntaxException: Not all code is in Soy V2 syntax (found tag {if strContains($field, "date")}…
1
vote
2 answers

google closure tool combo box get model

How to get object from select combomenuitem...?i tried e.target.getMenu().getModel() goog.ui.ComboBox