For this case you probably want to do something like
this http://play.golang.org/p/i3KYeKHrhy

Rendering a template to a string creates extra garbage. There can be cases
where you actually do want/need to do as you ask. In such cases do as David
On Wednesday, April 10, 2013 9:22:28 PM UTC-7, Jacob Arthur wrote:

I have a tenuous grasp on how io.Writer works so it's leading me to a
problem when I would like to take the writer that I pass into Execute and
put that value into a string.

Further explanation of what I am trying to do:

I'm trying to write a template like this

{{range .}}

where the data passed into Execute would be a slice of something with
Render() that also uses a different template

type Info struct {
Name string
Address string

func (i *Info) Render() string {
t, _ := template.ParseFiles("DisplayInfo.txt")
t.Execute( ?, i)

return [string of executed template]


Hi, {{.Name}}! You live at {{.Address}}


Perhaps there is a way to 'chain' the Writers? Or maybe there is a way to
tell the writer to write to a string?

You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 4 | next ›
Discussion Overview
groupgolang-nuts @
postedApr 11, '13 at 7:58a
activeApr 11, '13 at 5:51p



site design / logo © 2021 Grokbase