Package Usage: go: github.com/robfig/soy
Package soy is an implementation of Google's Closure Templates, which are
data-driven templates for generating HTML.
Compared to html/template, Closure Templates have a few advantages
and specific to this implementation:
Refer to the official language spec for details:
https://developers.google.com/closure/templates/
Here is Hello World
Here is a more customized version that addresses us by name and can use
greetings other than "Hello".
This last example renders a greeting for each person in a list of names.
It demonstrates a [foreach] loop with an [ifempty] command. It also shows how to
call other templates and insert their output using the [call] command. Note that
the [data="all"] attribute in the call command passes all of the caller's
template data to the callee template.
This example is from
https://developers.google.com/closure/templates/docs/helloworld_java.
Many more examples of Soy language features/commands may be seen here:
https://github.com/robfig/soy/blob/master/testdata/features.soy
These are the high level steps:
Typically in a web application you have a directory containing views for all of
your pages. For example:
This code snippet will parse a file of globals, all Soy templates within
app/views, and provide back a Tofu intance that can be used to render any
declared template. Additionally, if "mode == dev", it will watch the Soy files
for changes and update your compiled templates in the background (or log compile
errors to soy.Logger). Error checking is omitted.
On startup:
To render a page:
Structs may be used as the data context too, but keep in mind that they are
converted to data maps -- unlike html/template, the context is pure data, and
you can not call methods on it.
See soyhtml.StructOptions for knobs to control how your structs get converted to
data maps.
The goal is full compatibility and feature parity with the official Closure
Templates project.
The server-side templating functionality is well tested and nearly complete,
except for two notable areas: contextual autoescaping and
internationalization/bidi support. Contributions welcome.
The Javascript generation is early and lacks many generation options, but
it successfully passes the server-side template test suite. Note that it is
possible to run the official Soy compiler to generate your javascript templates
at build time, even if you use this package for server-side templates.
Please see the TODO file for features that have yet to be implemented.
Please open a Github Issue for any bugs / problems / comments, or if you find a
template that renders differently than with the official compiler.
3 versions
Latest release: about 2 years ago
3 dependent packages
View more package details: https://packages.ecosyste.ms/registries/proxy.golang.org/packages/github.com/robfig/soy
View more repository details: http://repos.ecosyste.ms/hosts/GitHub/repositories/robfig%2Fsoy
Dependent Repos 2
theothertomelliott/soyusage
Analyze parameter usage in soy templatesSize: 60.5 KB - Last synced: 11 months ago - Pushed: about 2 years ago

slinso/goTemplateBenchmark
comparing the performance of different template enginesSize: 269 KB - Last synced: 3 months ago - Pushed: 3 months ago

roger2000hk/goTemplateBenchmark Fork of slinso/goTemplateBenchmark
comparing the performance of different template enginesSize: 36.1 KB - Last synced: over 1 year ago - Pushed: about 9 years ago
