unrolled / render

Go package for easily rendering JSON, XML, binary data, and HTML templates responses.
MIT License
1.94k stars 146 forks source link

[WIP] Add function to render sub-template with specified binding #65

Closed lheinlen closed 6 years ago

lheinlen commented 6 years ago

From within a template, I need the ability to render a shared template and specify the binding based on the current context.

For example...

{{range .Items}}<tr><td>{{.Name}}</td><td>{{template "shared/actions" .Actions}}</td></tr>{{end}}

... where Actions is a property of each Item containing a slice of objects that is used to populate an actions dropdown menu.

I added this feature as a new function, template. Another option would be to alter partial to optionally accept a binding (by adding a ...interface{} parameter). Further, template may not be best name if a new function is used.

Since I was unsure about the most appropriate implementation/naming, I thought I'd go ahead and create a PR and then, if you are interested in this feature, make any modifications and add tests once that is done.

Thank you for the library!

unrolled commented 6 years ago

@lheinlen Is this still a work in progress?

lheinlen commented 6 years ago

@unrolled I'm currently using it as implemented in the PR. I was just waiting on your opinion of whether or not this seemed like a feature you would want to include (or whether you preferred a different name for the function, etc.). If it is, I'll write up the tests.

unrolled commented 6 years ago

I think subtemplate would be a good descriptive name (and maybe less confusing). Some tests would be greatly appreciated!

unrolled commented 6 years ago

Closing for now, please reopen if needed. Thanks!!