Questions tagged [go-templates]

Go language supports built-in template functionality. Packages with this support include 1) text/template and; 2) html/template.

Overview

Go language supports built-in template functionality. This is provided by the text/template and html/template packages. Go templates can be used as a minimal scripting language within command-line tools, or embedded in tools to produce larger files.

Features

Go language templates support most of the traditional features found in template-engines including, but not limited to:

  • comments
  • template variables and expressions
  • {{ }} template placeholder syntax (known as actions)

Related Tools

Go templates are widely used in the greater ecosystem. A template can be used to render output of the command-line tool, or in combination with the package manager to produce Kubernetes object manifests based on deploy-time settings.

Tag Guidance

Go templates are not Go code. Use the tag only if you are writing code that invokes one of the template packages; do not use it if you are writing template code using another tool using the template engine.

If you are using Go templates in the context of another tool such as or , also use the appropriate tag for that tool. If you are using a support library such as , it may be appropriate to include this tag as well.

Go templates share many aspects of traditional programming, including variables, loops, and subroutines. It is possible to use Go templates in non-programming contexts as well. For simple applications merely involving variable substitution or rendering a structure in the --format option of a command-line tool, consider whether your use is actually programming-related.

779 questions
-1
votes
1 answer

Redirect from one page to another not working

I am trying to Insert the scan results using the Scan func and once done I want to redirect to show results which are nothing but a select query to the inserts done ever. Both functions are working properly when tested separately. Is this not the…
Neo
  • 13
  • 5
-1
votes
1 answer

Nested ranges from directorys in helm

Having to generate templates based on the existence of certain files in the tree. the best i find to do this is with multiple ranges in the helm file and some ifs to check but it seams that helm does not like this kind of nesting. Chart tree ├──…
-1
votes
1 answer

template string and function concatenation

I try to template some JSON values in a go function, which basically works like I expect it. But if I try to concatenate the template string with a template function it fails (with different errors, depends on how the template string looks) For…
-1
votes
1 answer

Pass parameter to javascript function in Go template

I have the following in my Go's template. This is not working and I am getting this Javascript error : "Property assignment expected." This works…
Matias Barrios
  • 4,674
  • 3
  • 22
  • 49
-1
votes
2 answers

Template renders nothing, and no error, but status is 200

I'm playing with Go in a simple HTTP server: // var tpl = template.Must(template.New("").Funcs(template.FuncMap{"isRegistered": isRegistered}).ParseGlob("templates/*")) // functions will be added later var tpl =…
DoctorP
  • 159
  • 2
  • 10
-1
votes
1 answer

Specifying field name in anonymous maps

My program gets data from a TOML file for an embedded struct named Data: === [custom] Data = [ { filename = "fb.jpg", alt = "FB logo", url = "facebook.com" }, {…
tomcam
  • 4,625
  • 3
  • 19
  • 22
-1
votes
1 answer

Putting data to a Golang dropdown list

On my program I have a Product structure type Product struct{ SupplierId string Category1 string Category2 string DefaultColor string SupplierRef string } On the form I have …
bheki
  • 21
-1
votes
1 answer

Simple way to display image file with HTML forms section

I have been playing around with numerous go server snippets trying to figure out how I can display an image file within a HTML file or go HTTP template along with an html forms section. Basically, the biggest problem if I use a go template I cannot…
djoemart
  • 9
  • 4
-1
votes
2 answers

Golang templates won't load

I started to write a Gin application and my project tree looks like -assets --css ---{bootstrap} -templates --layouts ---footer.html ---head.html ---header.html --book.html -main.go In main.go I load templates and there is no…
Anton Motin
  • 51
  • 1
  • 7
-1
votes
1 answer

How to call a function on a custom type

I've seen some similar questions but I can't find one that solves my problem. I have a custom Money type that aliases int64 with a function that formats the value as a string: type Money int64 func (m *Money) Format() string { abs :=…
Matt
  • 3,677
  • 1
  • 14
  • 24
-1
votes
1 answer

Golang template generate values from array of strings error

Im using Golang project which needs to generate the following app1 && app2 && app3 My template look like following {{- range ExeApp .}} {{ .Command }} {{- end}} My code looks like following with command which is array of strings type App struct { …
07_05_GuyT
  • 2,787
  • 14
  • 43
  • 88
-1
votes
1 answer

Helm yaml keys from values.yaml

I want to make a yaml KEY (not the value) dynamically. In my values.yaml failoverip1: 0.0.0.0` (<- this is only a demo IP) In my templates/configmap.yaml I have this: apiVersion: v1 kind: ConfigMap metadata: name: vip-configmap data: {{-…
Jan
  • 12,992
  • 9
  • 53
  • 89
-1
votes
1 answer

golang error when serving static files

I can't figure out this error in go lang when executing a template panic: open templates/*.html: The system cannot find the path specified. another problem is that my public folder can't be served from css and I don't know why. code: package…
Ahmed Nader
  • 151
  • 5
  • 19
-1
votes
1 answer

Use Go .Variable inside range block in THTML file

I have a .thtml file: ...

{{.Something}}

{{range ...}}

{{.Something}}

{{end}}
... If I use the value of .Something inside the .thtml…
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
-1
votes
1 answer

Golang parsing template from third party lib

I am writing a library which is parsing templates from its template package. When I am using it within a sample application its reading the template from its own directory but the code in libary is failing. Here is the libary -…
Harshit Bangar
  • 293
  • 1
  • 4
  • 11
1 2 3
51
52