go-templates Questions

1

Solved

I have a struct of type Item that contains ItemFields which is a slice of type string. I would like to conditionally print each string in ItemFields that is a hyperlink with an anchor tag. To do so...
Unessential asked 12/1, 2019 at 22:53

2

Solved

I have a struct that contains a slice of type string like the following. type Data struct { DataFields []string } Within my html template file I would like to range over the string slice. Ho...
Orme asked 12/1, 2019 at 1:49

5

Solved

How do I get nested templates like Jinja has in the python runtime. TBC what I mean is how do I have a bunch of templates inherit from a base templates, just filing in blocks of the base templates,...
Hilbert asked 13/7, 2012 at 9:28

3

Solved

What is the namespace of variables inside html/text templates? I thought that a variable $x can change value inside a template, but this example shows me that I cannot. I failed when I tried to gr...
Jeuz asked 8/10, 2015 at 22:35

3

Solved

How can you calculate something inside a html template of go? For example: {{ $length := len . }} <p>The last index of this map is: {{ $length -1 }} </p> Were the . is a map. The co...
Led asked 15/10, 2018 at 10:38

1

Solved

So I have and html template when using this I get the object: <div>Foobar {{ index .Doc.Users 0}}</div> Output: <div>Foobar {MyName [email protected]}</div> I jus...
Cirsoid asked 6/10, 2018 at 19:27

1

I have a Prometheus alert like this: - alert: NginxCrashLoop annotations: description: Nginx at {{ $labels.pod }} is in Crash Loop identifier: '{{ $labels.node }}' runbook_url: https://sites.g...
Blasting asked 12/7, 2018 at 8:48

2

Solved

Helm _helpers.tpl? Helm allows for the use of Go templating in resource files for Kubernetes. A file named _helpers.tpl is usually used to define Go template helpers with this syntax: {{- defin...
Guileless asked 12/10, 2017 at 21:21

1

Solved

In to get the index number php: foreach much as index => each{ //get index number from index } How can I get the index number in go? {{ range .post }} {{ // how can i get index number? }} ...
Swivet asked 29/8, 2018 at 10:24

2

Solved

Template.ParseGlob("*.html") //fetches all html files from current directory. Template.ParseGlob("**/*.html") //Seems to only fetch at one level depth Im not looking for a "Walk" solution. Just w...
Debbiedebbra asked 9/9, 2014 at 13:19

3

Solved

I have this struct : const ( paragraph_hypothesis = 1<<iota paragraph_attachment = 1<<iota paragraph_menu = 1<<iota ) type Paragraph struct { Type int // paragraph_hypothesi...
Supertax asked 7/6, 2013 at 13:34

1

Solved

In Go's database/sql package, there are a bunch of Null[Type] structs that help map database values (and their possible nulls) into code. I'm trying to figure out how to test whether a struct field...
Obsecrate asked 4/7, 2018 at 4:11

1

Solved

Say I have {{ partial "li.html" $test $root.Data.Term }}. With this I can can access the first parameter, or $test, by simply refering to . within the li.html template, but how do I access the sec...
Feasible asked 30/8, 2017 at 14:34

4

Solved

In order to use revel's even keyword in templates I would like to get the index of a map entry when iterating with range. Is there any way to do so? My map has the structure: map[string][]string ...
Baeyer asked 22/3, 2017 at 10:12

2

Solved

This program outputs simply 1,4,2, but I would like to print 1,4,2. As you can see the comma is printed after each items of an array. package main import "os" import "text/template" fu...
Hydrography asked 29/4, 2018 at 9:13

2

Solved

So I am doing a simple if check on a bool from a struct but it doesn't seem to work, it just stop rendering the HTML. So the following struct is like this: type Category struct { ImageURL string...
Demonstration asked 8/11, 2016 at 19:21

1

Solved

I was trying to get a struct passed to a nested template in Go, using html/template and tried to achieve it using both template.ParseFiles and template.ParseGlob, but it is not working as per my ex...
Schnozzle asked 4/2, 2018 at 20:2

1

Solved

I have a nested loop: {{$columns := .columns}} {{range $dx := .dataList}} {{range $c := $columns}} {{index $dx $c}} {{end}} {{end}} dataList is the orm model array. With ID, Title fields , th...
Husserl asked 2/2, 2018 at 9:39

1

Solved

I work on a dev tool that uses templates for generating files such as readmes and licenses. Everything works fine apart from one instance of a < character gets turned into a < - the corr...
Chrysarobin asked 30/1, 2018 at 17:20

2

Solved

I'm trying to use a variable declared outside a Go template range loop to see if the previous post occurred on the same day as the current post. Here's a simplified example. Where .Posts is an arr...
Rights asked 23/2, 2015 at 12:48

1

Solved

I have a vector with n elements. I'm using it to render items in a template. But I need to render only the 5 first elements. Please note that is possible to have less than 5 elements in vector, in ...
Graphic asked 6/12, 2017 at 18:26

1

I have the following values.yaml: vrIds: - 51 - 52 51.vip: 169.254.1.1 52.vip: 169.254.1.2 I have the following template: {{ range $index, $element := .Values.vrIds }} vrrp.{{$element}}.vip:...
Susann asked 3/10, 2017 at 10:48

1

Solved

I am trying to add if great than condition in Helm chart. it is throwing error. I have defined value in values.yaml and using that value in deployment.yaml for condition. values.yaml replicaCoun...
Nissen asked 2/9, 2017 at 2:28

1

Solved

For example, there is a function like that: func TestFunc(str string) string { return strings.Trim(str," ") } It runs in the example below: {{ $var := printf "%s%s" "x" "y" }} {{ TestFunc ...
Gally asked 29/7, 2017 at 13:25

2

Solved

Having played around with Go HTML templates a bit, all the examples I found for looping over objects in templates were passing structs of slices to the template, somewhat like in this example : ty...
Tzong asked 3/7, 2014 at 14:9

© 2022 - 2024 — McMap. All rights reserved.