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
3
votes
1 answer

Auto rebuild closure soy templates

I faced a problem while using Google Closure Soy templates. When I change a template I need to run a script from command line to compile Soy template to JS file. Is there a service or something else to rebuild these templates automatically? Also,…
2
votes
1 answer

Custom Bitbucket Merge Check - dynamic fields render twice after submitting the configuration

I'm creating a custom Merge Check for Bitbucket. I started by following this tutorial: https://developer.atlassian.com/server/bitbucket/how-tos/hooks-merge-checks-guide/ I want the view to be dynamic, e.g. have button that creates multiple similar…
2
votes
1 answer

How to provide multiple dependencies in --chunk for closure compiler?

I have this requirement where i have test.js file dependent on x and y modules. So i was trying something like, The below code generates x and y successfully but breaks on producing the test module. How can i pass multiple dependencies? If we can't…
2
votes
0 answers

display soy variable value like alert in javascript

Do we have anything equivalent to javascript alert() in soy file to display variable values? I tried using javascript also in soy like below but didnt help (extendedFieldView is a List): <#assign extendedField =…
surm
  • 167
  • 2
  • 11
2
votes
2 answers

In Soy (Closure) templates, how can I print an expression that might be undefined at runtime?

Let's say the template model contains a map called $myMap whose keys are unknown at compile time. If my template attempts to print a map entry using {$myMap[$someValidKey]}, all is fine. However if I try to print using {$myMap[$someInvalidKey]}, the…
Andrew Swan
  • 13,427
  • 22
  • 69
  • 98
2
votes
1 answer

How to pass html parameter in Google Closure Template

Guys I want to pass a parameter that contains html characters in Google Closure Template, but all I get is literal html texts. How to do this? What I have tried so far is this : {template .modal autoescape="strict" kind="html"} …
user2881063
  • 1,049
  • 1
  • 10
  • 18
2
votes
1 answer

Closure templates from multiple soy files

I have a template called templates.soy and I would like to be able to call a template from a separate file (would like to overwrite that file programmatically from time to time). I can call a template within the same file. Currently I…
Wheeler
  • 454
  • 5
  • 17
2
votes
0 answers

Treat markup as translatable with SoyMsgExtractor

Is there a way to have HTML markup inside {msg} not turned into placeholders when using SoyMsgExtractor? Say I have some documentation: {msg desc="Document X, can contain HTML markup"}

Foo bar baz

Blah blah

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
2
votes
2 answers

Rewriting a property named "default" with Google Closure Templates

In the data that I send to a Google Closure template, I have a property named default. I plan on compiling both the JavaScript code and the code generated by SoyToJsSrcCompiler using the Google Closure Compiler. But the problem is that the generated…
2
votes
1 answer

Preferred method of recursive decoration in Closure

I'm looking for a way to take a document fragment (generated from a Soy template) in Google Closure and recursively decorate any elements with corresponding UI Components in the registry. It seems to me that this should be relatively simple to…
2
votes
1 answer

How can I append soy template return values as DOM nodes to the document body?

I am currently appending Google Closure Soy templates to the body of my HTML document via var header = app.ui.templates.home.header(); document.body.innerHTML = header + app.ui.templates.home.bottom({ "widgets": widgets, }); However, I…
dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206
2
votes
2 answers

How do I load dependencies in a soy template?

In my Google Closure code, I made an enum denoting names of CSS classes and want to use this enum in my soy template: /** * Lists a single widget. * @param widget The widget to be listed. */ {template .singleWidgetListing}
dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206
1
vote
1 answer

Using main layout template in closure templates

I'm using closure templates and I can't figure out how to have one main template with common stuff such as logo and when I render other templates they will be rendered inside the main one. I want to have a servlet for each template.
dan542
  • 15
  • 1
  • 4
1
vote
3 answers

How to check the map type?

I am setting the data in model as: @RequestMapping("/forms/builder/") public void renderMethod1(Model model) { SoyMapData x=new SoyMapData("class","menu horizontal right"); model.addAttribute("pageTitles", x); } Which is…
pihu
  • 93
  • 1
  • 11
1
vote
1 answer

What's the best practice for including CSS and javascript files in a java web project?

I've recently started on a new google app engine project that uses RestEasy for MVC and Gradle for our build process. Now I'm at a point where I want to include SASS, javascript, and closure template files but I'm unsure about how I should do this.…