Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

go-templates

Switch or if/elseif/else inside golang HTML templates

March 7, 2023 by Tarik

Yes, you can use {{else if .IsMenu}}

Categories html Tags go, go-templates, html, templates Leave a comment

If not true (!true)

February 20, 2023 by Tarik

Use the function not: {{ if not .loggedIn }} <h1>Not logged in</h1> {{ end }}

Categories if-statement Tags go, go-templates, if-statement Leave a comment

Is it possible to have nested templates in Go using the standard library?

January 15, 2023 by Tarik

Yes it is possible. A html.Template is actually a set of template files. If you execute a defined block in this set, it has access to all the other blocks defined in this set. If you create a map of such template sets on your own, you have basically the same flexibility that Jinja / … Read more

Categories go Tags go, go-templates Leave a comment

Access a map value using a variable key in a Go template

January 7, 2023 by Tarik

You use the index function: {{index .Amap “key1”}} index Returns the result of indexing its first argument by the following arguments. Thus “index x 1 2 3” is, in Go syntax, x[1][2][3]. Each indexed item must be a map, slice, or array. https://golang.org/pkg/text/template#hdr-Functions

Categories go Tags go, go-templates, templates Leave a comment

Iterating through map in template

December 19, 2022 by Tarik

Check the Variables section in the Go template docs. A range may declare two variables, separated by a comma. The following should work: {{ range $key, $value := . }} <li><strong>{{ $key }}</strong>: {{ $value }}</li> {{ end }}

Categories go Tags go, go-templates Leave a comment
Newer posts
← Previous Page1 Page2 Page3

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa