New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
text/template: can invoke method of pipeline result value #28577
Comments
@runner-mei I assume that this is a feature request to be able to chain methods via pipelines, is that correct? Have you considered doing something like Also note that currently the parser is the one that rejects undefined functions. If this feature were to get implemented, we'd have to drop that check entirely, as it would be impossible to tell if a function is defined or not at parse time. I personally think this is not a good idea. It seems like you can already accomplish the task with the current template language, and we don't want to complicate the language unless strictly necessary. /cc @robpike |
@mvdan yes, this is a feature request to be able to chain methods via pipelines. no, We didn't give up that check entirely,result of function text_field is *TextField (not interface{}), We can try to obtain the return value type and check it. |
I would prefer not to do this. The grammar is subtle enough as is, the execution logic even more so, and it is easy, as shown above, to achieve the desired result with the existing template language. |
@robpike Now the grammar is insufficient, it is cumbersome。 It's a bug? the following statements are incorrect, they run ok and don't have any output
only the following statements are correct
|
or add '@' prefix
|
can invoke method of pipeline result value
text_field return *TextField ptr,
"|SetValue .value" will invoke "func (field *TextField) SetValue( value string)"
"|Render" will invoke "func (field *TextField) Render()"
like
if method isnot exists then execute old behaviour.
My English is poor.
我的意恩是
现在模板将符号 '|' 之前的执行结果作来下一个方法(function)的最后一个参数, 那能不能将 '|' 后的方法作为前一次结果的成员函数(method),
The text was updated successfully, but these errors were encountered: