Questions tagged [go-html-template]

Relating to using the html/template package. This package is similar to the text/template package but has logic relating to html, url, and javascript escaping as well a generating html.

Relating to using the html/template package. This package is similar to the text/template package but has logic relating to html, url, and javascript escaping as well a generating html.

98 questions
1
vote
1 answer

How to set a variable for an external HTML template in Go?

I've two Go templates. top.html: {{ .title }} and register.html: {{ template "top.html" . }} …
danny
  • 11
  • 2
1
vote
1 answer

Sort slice in golang html/template?

I have a slice like [{0 1} {0 3} {0 2}]. Order is random. I'd like to output them in order of second argument. {{range .Slice}} would return them in the order of indexed position. I would use something like {{range .Slice|sortBy .[1]}} but there is…
Maciej Wakuła
  • 125
  • 1
  • 9
1
vote
1 answer

How to stop go html/template from escaping a path (tried .HTML .JS etc.)

I am using the html/template functionality to assemble a page and on of the variables I'm supplying to the template is URI in the form "/some/path/etc" which is used as a parameter to a JS function called in a onClick="..". No matter what, the…
KaMaCh
  • 19
  • 3
1
vote
1 answer

Template partially rendering as plaintext

I'm having trouble with one particular thing I'm trying to put through Go html templates. (all will be condensed/simplified for brevity) I have one base template: {{ .Title }}
T1960CT
  • 407
  • 7
  • 18
1
vote
1 answer

Using a Go Template var inside of a `{{ template }}`

In Go we can create a variable easily enough with {{- if .Bool.Var -}} {{ $MyVar := "val" }} {{- end -}} We can even create shared snippets easily enough {{- define "val" -}}

Some shared template data

{{- end -}} My question is, how do…
Jordon Bedwell
  • 3,189
  • 3
  • 23
  • 32
1
vote
1 answer

rendering html templates golang revel

I am hoping someone will be able to help me out. I have started building a web app and decided to go with GO and Revel. So far I've learnt quite a few things but there is this one functionality I can't seem to be able to get working. I have the…
1
vote
1 answer

With Echo and html/template how can I pass HTML to the template?

I'm using Echo to build my first small Go web service and I went with the example they provide for using html/template for HTML page templates to simplify page management. On one of the pages I'm collecting data from a backend API and wanted to…
Nathan V
  • 455
  • 7
  • 12
1
vote
0 answers

Selecting among multiple Go subtemplates based on one value in a template

I'm a newbie Go (and Go templates) amateur programmer, and I have seen variants of this question being asked, but never quite in the same way, so here it goes again... I'm attempting to do the following without registering any additional functions…
Gwyneth Llewelyn
  • 796
  • 1
  • 11
  • 27
1
vote
1 answer

Go Template : Use nested struct's field and {{range}} tag together

I have the following nested struct and I would like to iterate them in a template, in a {{range .Foos}} tag. type Foo struct { Field1, Field2 string } type NestedStruct struct { NestedStructID string Foos []Foo } I'm trying with the…
Doby
  • 75
  • 2
  • 11
1
vote
2 answers

How to execute multiple templates in a single webpage using different interfaces in golang?

Please forgive me for a weird looking question. I wasn't sure exactly how to state my problem in a single statement. I have three templates in my webpage, header, layout and footer. In the template header, I have a categories dropdown menu and I…
Krash
  • 2,085
  • 3
  • 13
  • 36
1
vote
1 answer

GO html/template: test equality of two dot variables

I'm sending an html/template this model: type MapModel struct { Networks []*NetworkMeta WaveKey string } The Networks field is defined by another type, NetworkMeta: type NetworkMeta struct { NetworkMetaKey string } I use the Networks…
Brent
  • 805
  • 9
  • 20
1
vote
1 answer

Combining first function with index in golang/html template

I'm creating a blog with Hugo. i would like to list the first 3 Blog entries. That is not a problem so far. {{ range first 3 .Data.Pages.ByPublishDate }} But i need the index for adding css classes. I do that with this line {{ range $index,…
DamirDiz
  • 701
  • 2
  • 10
  • 15
1
vote
0 answers

html template with martini in golang

I have problem with go, martini and how martini works with templates. package main import ( "github.com/go-martini/martini" "github.com/martini-contrib/render" ) type Page struct { Caption string Body string Tmpl …
insomniac669
  • 57
  • 1
  • 7
1
vote
2 answers

Go - html/template, template.ParseGlob() and code re-use

I'm trying to get my head around embedding templates using html/template in Go. I very much like the logic-less template design and I have confidence in its ability to safely escape things as expected (sometimes other template libs get this…
elithrar
  • 23,364
  • 10
  • 85
  • 104
0
votes
0 answers

Dynically Update Ascii-Art Color with Golang HTML/Template

I'm creating an Ascii-Art web app that takes a text input and displays the ascii-art version of the text. I'm trying to color the art, getting a hex color value from a colorpicker, and then parsing this back into the HTML to change the color. But…