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
54
votes
3 answers

How to compare the length of a list in html/template in golang?

I am trying to compare the length of a list in golang html/template. But it is loading forever in html. {{ $length := len .SearchData }} {{ if eq $length "0" }} Sorry. No matching results found {{ end }} Could anyone help me with this?
Dany
  • 2,692
  • 7
  • 44
  • 67
20
votes
4 answers

Format float in golang html/template

I want to format float64 value to 2 decimal places in golang html/template say in index.html file. In .go file I can format like: strconv.FormatFloat(value, 'f', 2, 32) But I don't know how to format it in template. I am using gin-gonic/gin…
Bhavana
  • 1,014
  • 4
  • 17
  • 26
14
votes
3 answers

How can I control whitespace after an action in html/template?

I am having a problem controlling whitespace and still formatting html/template templates in a readable fashion. My templates look somthing like this: layout.tmpl {{define "layout"}} …
Chas. Owens
  • 64,182
  • 22
  • 135
  • 226
12
votes
1 answer

How to not escape in HTML templates

Trying to render HTML templates for sending via email with embedded attachments with cid:. Problem is, that Go does escaping and I cannot do anything. tplVars := map[string]interface{}{ "Dog": "cid:dog.png", "Cat": "cid:cat.png", } My…
Arxeiss
  • 976
  • 16
  • 34
12
votes
6 answers

Slow performance of html/template in Go lang, any workaround?

I'm stress testing (with loader.io) this type of code in Go to create an array of 100 items along with some other basic variables and parse them all in the template: package main import ( "html/template" "net/http" ) var templates…
uiwe83
  • 163
  • 1
  • 10
10
votes
1 answer

How to get rid of ZgotmplZ from html/template in Golang?

I'm using Golang in backend. When I render the html using html/templates I'm getting ZgotmplZ for URL's. {{if .UserData.GitURL}}
  • {{end}} I'm using string for…
    Dany
    • 2,692
    • 7
    • 44
    • 67
    9
    votes
    2 answers

    mgo convert bson.objectId to string(hex) in html template

    I know this problem maybe duplicate to this one. But it hasn't get a satisfied answer till now. And I really want to draw some attention to get a solution as soon as possible. So I beg you not to close this issue unless you have the solution and…
    armnotstrong
    • 8,605
    • 16
    • 65
    • 130
    8
    votes
    2 answers

    How to specify the file location for `template.ParseFiles` in Go Language?

    After I watched this video, I try it myself. However, I get the panic error panic: open templates/index.html: The system cannot find the path specified. The Complete erroe message is like the following. Hello, Go Web Development 1.3 panic: open…
    Casper
    • 4,435
    • 10
    • 41
    • 72
    8
    votes
    2 answers

    How to validate html email templates?

    I am using telerik reporting tool to generate reports in different formats, .pdf,.html, .doc, .txt etc. Some of our client's email server doesn't sport attachment in emails so I want to embed the .html report to my email body instead of attaching it…
    R K Sharma
    • 845
    • 8
    • 23
    • 42
    6
    votes
    1 answer

    Parsing unescaped HTML to HTML template in Go

    I have created this really simple program for testing. package main import ( "fmt" "github.com/microcosm-cc/bluemonday" "github.com/pressly/chi" "github.com/russross/blackfriday" "github.com/unrolled/render" …
    fisker
    • 979
    • 4
    • 18
    • 28
    5
    votes
    2 answers

    Simple if not working go template

    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 Title string Description …
    Steve
    • 1,213
    • 5
    • 16
    • 29
    5
    votes
    2 answers

    Sort on user defined properties

    I'm using hugo v0.15 I'm trying to sort pages on custom property. I define my subpages as following: +++ title= "bla bla bla" parent = "parent" index = 0 # each page is assigned a unique index +++ And in my parent template as following: {{ range…
    Amr M. AbdulRahman
    • 1,820
    • 3
    • 14
    • 22
    5
    votes
    1 answer

    How to iterate over keys and values of a map in a Go html template

    I have a template in go using the http/template package. How do I iterate over both the keys and values in the template? Example code : template := `

    Test Match

      {{range .}}
    • {{.}}
    sheki
    • 8,991
    • 13
    • 50
    • 69
    4
    votes
    1 answer

    In html/templates is there any way to have a constant header/footer across all pages?

    Reading the docs wasn't particularly helpful and I want to know if the structure {{header}} {{content that always changes}} {{footer}} is achievable with golang.
    m0meni
    • 16,006
    • 16
    • 82
    • 141
    3
    votes
    1 answer

    How can I run a range within a range in golang using html/template

    I want to run a range within a range using html/template. The sample code (https://go.dev/play/p/fxx61RwIDhd) looks like this: package main import ( "html/template" "os" ) type Runtest struct { ID int SessionType…
    nexty5
    • 47
    • 6
    1
    2 3 4 5 6 7