Golang模板中的呼叫链接

Suppose you have the following code

router.Get("foo").URL("id", id)

If I want to do something similar in a go template. I believe I have to go the long way and create an intermediary variable.

{{ $urlGenerator := .Router.Get "foo" }}
{{ $urlGenerator.URL "id" .Id }}

Preferably it would look like something like this

{{ (.Router.Get "foo") .Url }}

Or simply

{{ .Router.Get("foo").Url }}

Has anyone found a way that works a little like this? I can not find anything in the documentation regarding this, other than pipes, which works as... pipes.

It's in the very end of the Arguments paragraph of the text/template package doc:

  • A parenthesized instance of one the above, for grouping. The result may be accessed by a field or map key invocation:
    • print (.F1 arg1) (.F2 arg2)
    • (.StructValuedMethod "arg").Field