Thanks Matt.

What I'm trying to do is to modulelize customized Go template functions,
say one module provide advanced regexp support, while another one
specialized in text formatting (vertical aligning, text folding in column,
etc), so on and so forth, *each of the module has a collection of their
own customized template functions*.

The goal is to define such modules separately, as a building block, provide
them as libraries, and the end user can pick and choose what what, and
chain the customized template functions together using a series of `.Funcs`
calls.

That's what I had in mind. Hope that I've express it clear enough. Thx.


On Sun, Jul 9, 2017 at 10:20 PM, Matt Harden <matt.har...@gmail.com> wrote:

> Why are you trying to do that? It feels like you're trying to do
> object-oriented programming in Go. Don't do that. What are you trying to
> achieve that the *template.Template type doesn't allow?
>
> If you just want a template with a FuncMap already applied, write a
> function to do that:
>
> func MyTemplate(name string) *template.Template {
>     return template.New(name).Funcs(map[string]interface{}{"title":
> strings.Title})
> }
>
>
> On Thu, Jul 6, 2017 at 8:01 PM Tong Sun <suntong...@gmail.com> wrote:
>
>> I'm trying my best to make the following Go template FuncMap example
>> works:
>>
>> https://play.golang.org/p/1-JYseLBUF
>>
>> If I comment out line 55, 56 and un-comment line 54, it works just fine.
>>
>> What I was trying to do is to un-comment line 31, and use DefaultFuncs()
>> or something alike to replace line 54. I.e., I'm trying to wrap
>> the myFuncMap into a callable function.
>>
>> How can I do that? Thx
>>
>>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to