-
Notifications
You must be signed in to change notification settings - Fork 445
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
Feature Request: add "yield" function #387
Comments
Not with
It's certainly not as nice as having a dedicated function, but it works well enough for us. |
@forquare Thanks for your contribution. I am not entirely sure I can follow your example. May I ask you to elaborate. In particular what is |
On a side note: Hugo does provide include functionality for Go templates, see https://gohugo.io/templates/introduction/#includes |
@breml Firstly, let me apologise because I'm not sure how Helm does this, but I think they do some kind of preprocessing - I've tried this with my limited Go knowledge and can't replicate my suggestion simply using Go Secondly, apologies for not expanding. Despite the fact that what I said may not be valid! Let me still expand:
In my example,
However I think you would need to have some sort of preprocessing in place to handle this, as my limited knowledge cant' replicate this simply in Go. |
@forquare Thanks for the additional context. As you have written,
The key is "template is an action, and not a function". Additionally to the limitation, that it does not allow the output to be passed to an other function, it is also more strict about the "arguments" it accepts. The first argument (name of the template) is required to be a string constant and it is not possible to pass the name of the template as a variable. The error, the Both these limitations are removed by either the |
With Go templates it is not possible to dynamically (based on a variable) include other templates (partials). For example the following is not a valid Go template:
and it will produce the following error:
Since I had this problem already multiple times, I created a function
yield
, which does the same astemplate
, but allows the template name (first argument) to by dynamic (it can be a variable).With the new function
yield
, the following becomes possible:I think, this would be a meaning full addition to https://github.com/Masterminds/sprig and I am happy to provide a PR for this. What do you think?
The text was updated successfully, but these errors were encountered: