Documentation
¶
Index ¶
- Variables
- func Abs(n any) float64
- func Add(name string, f any)
- func After(t time.Time, tt string) bool
- func Before(t time.Time, tt string) bool
- func Cat(args ...any) string
- func Checkbox(current any, name string) template.HTML
- func Checked(vals []int64, id int64) template.HTMLAttr
- func Contains(slice any, find any) bool
- func Deref(s any) any
- func Div(n, n2 any, n3 ...any) any
- func Duration(a any, format string) string
- func Elide(s string, n int) string
- func HasPrefix(s, prefix string) bool
- func HasSuffix(s, suffix string) bool
- func If2(cond bool, yes any, no ...any) any
- func Int(n any) int64
- func IsInf(n float64) bool
- func JSON(v any) string
- func JSONPretty(v any) string
- func LargeNumber(n any, sep ...rune) string
- func Map(values ...any) map[string]any
- func Max(a, b any) float64
- func Min(a, b any) float64
- func Mult(n, n2 any, n3 ...any) any
- func Number(n any, sep ...rune) string
- func OptionValue(current, value string) template.HTMLAttr
- func Round(n any, to int) float64
- func Size(n any, format ...string) string
- func Slug(s string) string
- func String(v any) string
- func Sub(n, n2 any, n3 ...any) any
- func Substr(s string, i, j int) string
- func Sum(n, n2 any, n3 ...any) any
- func Time(a any, format string) string
- func UCFirst(s string) string
- func Unsafe(s any) template.HTML
- func UnsafeJS(s string) template.JS
Constants ¶
This section is empty.
Variables ¶
var FuncMap = template.FuncMap{ "int": Int, "sum": Sum, "sub": Sub, "mult": Mult, "div": Div, "round": Round, "abs": Abs, "is_inf": IsInf, "min": Min, "max": Max, "substr": Substr, "elide": Elide, "has_prefix": HasPrefix, "has_suffix": HasSuffix, "join": strings.Join, "ucfirst": UCFirst, "cat": Cat, "deref": Deref, "if2": If2, "map": Map, "contains": Contains, "before": Before, "after": After, "json": JSON, "json_pretty": JSONPretty, "number": Number, "large_number": LargeNumber, "time": Time, "duration": Duration, "size": Size, "slug": Slug, }
FuncMap contains all the template functions.
var FuncMapHTML = map[string]any{ "unsafe": Unsafe, "unsafe_js": UnsafeJS, "checkbox": Checkbox, "checked": Checked, "option_value": OptionValue, }
Functions ¶
func Checkbox ¶
Checkbox adds a checkbox; if current is true then it's checked.
It also adds a hidden input with the value "off" so that's sent to the server when the checkbox isn't sent, which greatly simplifies backend handling.
func Int ¶
Int converts any int, float, or string to an integer.
Floats are always rounded down; strings and []byte is parsed as a base-10 number. Any other type will panic.
func LargeNumber ¶
LargeNumber formats a number, adding the suffix "M" for values larger than a million or "k" for values larger than 100,000.
This loses some accuracy.
func Number ¶
Number formats a number with thousand separators using the separator sep.
For floats it will always use '.' as the digit separator, unless sep is set to '.' in which case it will use ','.
func OptionValue ¶
OptionValue inserts the value attribute, and selected attribute if the value is the same as current.
func Size ¶
Size formats a file size.
The optional parameter max gives the highest unit to format it as. Values for this can be 'b', 'k', 'm', 'g, 't', 'p'.
The format string controls some formatting aspects, as key/value pairs:
min=n max=n from=n
func Time ¶
Time formats a time as the given format string.
Return empty string if the time is nil or the zero value.
Types ¶
This section is empty.