Pipelines are nice, but sometimes the way to pass the right data to the right template looks awkward to me.
Let's say you have a site for Gophers about Gophers. It has a home page main template, and a utility template to print a list of Gophers.
http://play.golang.org/p/Jivy_WPh16Now if I want to add some tiny bit of context in the subtemplate, well I can't because there is only one possible "dot" pipeline! What can I do?
Obviously I can copy-paste the subtemplate code into the main template (no way I do that).
Or I can juggle with some kind of global variables with accessors (no way I do that).
Or I can create a new specific struct for each template parameter list (not great).
The best i've found so far (and I don't really like it) is muxing and demuxing parameters with a "generic" pair container :
http://play.golang.org/p/ri3wMAubPXtype PipelineDecorator struct {
// The actual pipeline
Data interface{}
// Some helper data passed as "second pipeline"
Deco interface{}
}
func decorate(data interface{}, deco interface{}) *PipelineDecorator {
return &PipelineDecorator{
Data: data,
Deco: deco,
}
}
This is no theoretical problem, I actually use this trick a lot for building my website, and I wonder if there exist some more idiomatic way to achieve the same.
I would surely be happy if some future backward-compatible change in the template syntax allows passing multiple pipeline parameters, just like functions do.
Any thoughts ?
Best regards