HTML()
The HTML()
SINK generates an HTML document or an element as output, using the provided template language for formatting.
This allows you to fully customize the structure and appearance of the HTML output based on your query results.
Syntax: HTML(templates...)
Since v8.0.53
templates
: One or more template strings orfile(path)
references. Each argument can be a direct template string or a file path usingfile(path)
to load the template from a file. The template content uses the Go HTML template language. For more information, see the template documentation.cache()
cache result data. see Cache Result Data for details.
Within the template, you have access to a value object that exposes the current record’s field values and row number. The following fields and properties are available within the HTML template context:
Methods
{{ .Columns }}
{{ .Column <idx>}}
{{ .Values }}
{{ .Value <idx> }}
{{ .ValueHTMLAttr <idx> }}
{{ .ValueCSS <idx> }}
{{ .ValueJS <idx> }}
{{ .ValueURL <idx> }}
{{ .ValueString <idx> }}
{{ .V.<field> }}
{{ .Num }}
Functions
timeformat
Syntax
{{ timeformat <format> <timezone> }}
Usage example
|
|
<li>2025-05-29T08:32:33Z
<li>Hello World
format
Usage example
|
|
<li> 3.14
<li> Say: Hello World?
param
|
|
- Invoke the TQL script with parameters
?param=Line
.
<li> Line 3.1415
<li> Line Hello World
paramDefault
|
|
<li> Line1 3.1415
<li> Line2 Hello World
toLower
|
|
<li> 3.14
<li> Say: hello world?
toUpper
|
|
<li> 3.14
<li> Say: HELLO WORLD?
Usages
.V
is a map object containing field names as keys and their corresponding values.
|
|

.Value
is a function that accesses the fields of the current record by their index.
|
|

.Values
is an array containing all field values of the current record.
|
|

Contexts
The template understands HTML, CSS, JavaScript and URIs. It adds sanitizing functions to each simple action pipeline, so given the excerpt.
Each {{.Value 0}}
, {{.Value 1}}
, and {{.Value 2}}
is overwritten to add escaping functions as necessary. In this case it becomes
|
|
- Output:
<li>
<a href="http://maven.org/">
<img src="https://docs.machbase.com/images/java_logo_32.png">Java
</a>
</li>
<li>
<a href="http://npmjs.com/">
<img src="https://docs.machbase.com/images/js_logo_32.png">JavaScript
</a>
</li>
Assuming {{.Value 0}}
is O'Reilly: How are <i>you</i>?
,
the examples below shows how {{.Value 0}}
appears when used in context.
|
|
|
|
|
|
SCRIPT({ $.yield(`Hello World?`, `function doMsg(msg){ console.log(msg); }`) })
HTML({
<script>
{{.ValueJS 1}}
</script>
<a onClick='doMsg("{{.Value 0}}")'>here</a>
})
// Output:
// <script>
// function doMsg(msg){ console.log(msg); }
// </script>
// <a onClick='doMsg("Hello World?")'>here</a>
Non-string values can be used in JavaScript contexts. If the record is an object:
in the escaped template
|
|
then template output is
<script>var pair = {"A":"foo","B":"bar"};</script>
Unescaped Strings
By default, the template assumes that all pipelines produce a plain text string. It adds escaping pipline stages necessary to correctly and safely embed that plain text string in the appropriate context.
When a data value is not plain text, you can make sure it is not over-escaped by marking it with its type.
Types HTML, JS, URL, and others can carry safe content that is exempted from escaping.
The template:
|
|
to produce
Hello, <b>World</b>!
instead of
Hello, <b>World<b>!