Package Usage: go: github.com/alecthomas/template
Package template implements data-driven templates for generating textual output.
To generate HTML output, see package html/template, which has the same interface
as this package but automatically secures HTML output against certain attacks.
Templates are executed by applying them to a data structure. Annotations in the
template refer to elements of the data structure (typically a field of a struct
or a key in a map) to control execution and derive values to be displayed.
Execution of the template walks the structure and sets the cursor, represented
by a period '.' and called "dot", to the value at the current location in the
structure as execution proceeds.
The input text for a template is UTF-8-encoded text in any format.
"Actions"--data evaluations or control structures--are delimited by
"{{" and "}}"; all text outside actions is copied to the output unchanged.
Actions may not span newlines, although comments can.
Once parsed, a template may be executed safely in parallel.
Here is a trivial example that prints "17 items are made of wool".
More intricate examples appear below.
Here is the list of actions. "Arguments" and "pipelines" are evaluations of
data, defined in detail below.
An argument is a simple value, denoted by one of the following.
Arguments may evaluate to any type; if they are pointers the implementation
automatically indirects to the base type when required.
If an evaluation yields a function value, such as a function-valued
field of a struct, the function is not invoked automatically, but it
can be used as a truth value for an if action and the like. To invoke
it, use the call function, defined below.
A pipeline is a possibly chained sequence of "commands". A command is a simple
value (argument) or a function or method call, possibly with multiple arguments:
A pipeline may be "chained" by separating a sequence of commands with pipeline
characters '|'. In a chained pipeline, the result of the each command is
passed as the last argument of the following command. The output of the final
command in the pipeline is the value of the pipeline.
The output of a command will be either one value or two values, the second of
which has type error. If that second value is present and evaluates to
non-nil, execution terminates and the error is returned to the caller of
Execute.
A pipeline inside an action may initialize a variable to capture the result.
The initialization has syntax
where $variable is the name of the variable. An action that declares a
variable produces no output.
If a "range" action initializes a variable, the variable is set to the
successive elements of the iteration. Also, a "range" may declare two
variables, separated by a comma:
in which case $index and $element are set to the successive values of the
array/slice index or map key and element, respectively. Note that if there is
only one variable, it is assigned the element; this is opposite to the
convention in Go range clauses.
A variable's scope extends to the "end" action of the control structure ("if",
"with", or "range") in which it is declared, or to the end of the template if
there is no such control structure. A template invocation does not inherit
variables from the point of its invocation.
When execution begins, $ is set to the data argument passed to Execute, that is,
to the starting value of dot.
Here are some example one-line templates demonstrating pipelines and variables.
All produce the quoted word "output":
During execution functions are found in two function maps: first in the
template, then in the global function map. By default, no functions are defined
in the template but the Funcs method can be used to add them.
Predefined global functions are named as follows.
The boolean functions take any zero value to be false and a non-zero
value to be true.
There is also a set of binary comparison operators defined as
functions:
For simpler multi-way equality tests, eq (only) accepts two or more
arguments and compares the second and subsequent to the first,
returning in effect
(Unlike with || in Go, however, eq is a function call and all the
arguments will be evaluated.)
The comparison functions work on basic types only (or named basic
types, such as "type Celsius float32"). They implement the Go rules
for comparison of values, except that size and exact type are
ignored, so any integer value, signed or unsigned, may be compared
with any other integer value. (The arithmetic value is compared,
not the bit pattern, so all negative integers are less than all
unsigned integers.) However, as usual, one may not compare an int
with a float32 and so on.
Each template is named by a string specified when it is created. Also, each
template is associated with zero or more other templates that it may invoke by
name; such associations are transitive and form a name space of templates.
A template may use a template invocation to instantiate another associated
template; see the explanation of the "template" action above. The name must be
that of a template associated with the template that contains the invocation.
When parsing a template, another template may be defined and associated with the
template being parsed. Template definitions must appear at the top level of the
template, much like global variables in a Go program.
The syntax of such definitions is to surround each template declaration with a
"define" and "end" action.
The define action names the template being created by providing a string
constant. Here is a simple example:
This defines two templates, T1 and T2, and a third T3 that invokes the other two
when it is executed. Finally it invokes T3. If executed this template will
produce the text
By construction, a template may reside in only one association. If it's
necessary to have a template addressable from multiple associations, the
template definition must be parsed multiple times to create distinct *Template
values, or must be copied with the Clone or AddParseTree method.
Parse may be called multiple times to assemble the various associated templates;
see the ParseFiles and ParseGlob functions and methods for simple ways to parse
related templates stored in files.
A template may be executed directly or through ExecuteTemplate, which executes
an associated template identified by name. To invoke our example above, we
might write,
or to invoke a particular template explicitly by name,
2 versions
Latest release: almost 6 years ago
5,792 dependent packages
View more package details: https://packages.ecosystem.code.gouv.fr/registries/proxy.golang.org/packages/github.com/alecthomas/template
Dependent Repos 25
1024pix/steampipe-plugin-learningcontent
Steampipe plugin to query LCMS contentSize: 101 KB - Last synced: 4 days ago - Pushed: over 1 year ago

1024pix/steampipe-plugin-metabase
Use SQL to query databases, tables, permissions and more from MetabaseSize: 1.22 MB - Last synced: 4 days ago - Pushed: 5 days ago

pocs/mdl-qor-sdk
This SDK is based upon [QOR](https://github.com/qor/qor) and aims to provide a boilerplate for quickly prototyping admin types applications.Last synced: 7 months ago - Pushed: 11 months ago
swh/infra/ci-cd/3rdparty/cert-manager-webhook-gandi
Last synced: 7 months ago - Pushed: 11 months ago
betagouv/sealed-secrets Fork of bitnami-labs/sealed-secrets
A Kubernetes controller and tool for one-way encrypted SecretsSize: 19.2 MB - Last synced: about 15 hours ago - Pushed: almost 3 years ago

cea-hpc/fabricmon Fork of dswarbrick/fabricmon
InfiniBand fabric monitoring daemon written in GoSize: 404 KB - Last synced: 1 day ago - Pushed: 6 months ago

cea-hpc/slurm_exporter Fork of vpenso/prometheus-slurm-exporter
Prometheus exporter for performance metrics from Slurm.Size: 3.02 MB - Last synced: 1 day ago - Pushed: 11 months ago

radiofrance/icecast_exporter Fork of markuslindenberg/icecast_exporter
Icecast exporter for PrometheusSize: 21.5 KB - Last synced: about 16 hours ago - Pushed: over 1 year ago

radiofrance/ipahealthcheck_exporter Fork of camptocamp/ipahealthcheck_exporter
Prometheus exporter for exposing ipa-healthcheck tool checks as metricsSize: 60.5 KB - Last synced: about 16 hours ago - Pushed: almost 4 years ago

radiofrance/process-exporter Fork of ncabatoff/process-exporter
Prometheus exporter that mines /proc to report on selected processesSize: 2.25 MB - Last synced: about 16 hours ago - Pushed: over 1 year ago

radiofrance/prometheus-logstash-exporter Fork of alxrem/prometheus-logstash-exporter 📦
Prometheus exporter for Logstash metricsSize: 1.31 MB - Last synced: about 16 hours ago - Pushed: about 5 years ago

signaux-faibles/wekan-alerter
wekan-alerterSize: 44.9 KB - Last synced: about 21 hours ago - Pushed: over 2 years ago

signaux-faibles/goup
Serveur minimaliste pour téléverser des fichiers avec une gestion de droitsSize: 63.1 MB - Last synced: about 21 hours ago - Pushed: over 2 years ago


betagouv/pc-dashboard 📦
Size: 158 MB - Last synced: about 15 hours ago - Pushed: over 5 years ago

radiofrance/helm-chart-sonarqube Fork of SonarSource/helm-chart-sonarqube
Size: 2.99 MB - Last synced: 7 months ago - Pushed: 9 months ago

web-et-numerique/factory/llle_project/cozy-stack
Fork of cozy-stack https://github.com/cozy/cozy-stackLast synced: 7 months ago

igrida/prometheus-oar-exporter
Exporter Prometheus pour les métrics du serveur OARLast synced: 7 months ago