Top 3.4% dependent packages on proxy.golang.org
Top 3.5% dependent repos on proxy.golang.org
Top 3.8% forks on proxy.golang.org
proxy.golang.org : 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.
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/robfig/soy
License: MIT
Latest release: about 2 years ago
First release: about 11 years ago
Namespace: github.com/robfig
Dependent packages: 3
Dependent repositories: 2
Stars: 168 on GitHub
Forks: 41 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 4 days ago