# Learn Go template
Go template (opens new window) library is a powerful library. Some examples can be found below. repeatit.io (opens new window) is a great place to learn/practice templating. Following examples will redirect you to the repeatit.io (opens new window).
# Use a value as text
If you have a value, for example Port
, and want to write its value as text, you should write it between
delimiters {{
}}
with a leading .
as
{{.Port}}
See the examples:
Port Example (opens new window)
Mail Example (opens new window)
# If, else if, else
Go template library allows you to do conditional rendering with if
statements . You can use following keywords in if
statements to compare values
eq
Returns the boolean truth of arg1 == arg2
ne
Returns the boolean truth of arg1 != arg2
lt
Returns the boolean truth of arg1 < arg2
le
Returns the boolean truth of arg1 <= arg2
gt
Returns the boolean truth of arg1 > arg2
ge
Returns the boolean truth of arg1 >= arg2
See examples:
HTTP server example (opens new window)
To check boolean (opens new window)
# Iterate an array and map
Go template allows you to iterate an array or a map.
See examples: