Comments (5)
@forquare Thanks for the additional context. As you have written, include
is a function provided by helm (source code: https://github.com/helm/helm/blob/e81f6140ddb22bc99a08f7409522a8dbe5338ee3/pkg/engine/engine.go#L129), which works similar to the function yield
that I am proposing in this issue.
In the documentation you linked above there is a statement about template
, which explains why your snippet does not work:
Because template is an action, and not a function, there is no way to pass the output of a template call to other functions; the data is simply inserted inline.
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 template
action produces, if the name is not a string constant (but a variable) is provided in the initial description of this issue.
Both these limitations are removed by either the yield
function proposed here or the include
function available in helm.
from sprig.
Not with template
, but we have a pattern like this for include
s:
{{ include (printf "%s" $template) . }}
It's certainly not as nice as having a dedicated function, but it works well enough for us.
from sprig.
@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 $template
(filename, name of the thing to include, the content to be included (plain text), the content to be included, but rendered as a Go template, something else) and what does the include
function exactly do. Thanks.
from sprig.
On a side note: Hugo does provide include functionality for Go templates, see https://gohugo.io/templates/introduction/#includes
from sprig.
@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 text/template
.
Secondly, apologies for not expanding. Despite the fact that what I said may not be valid! Let me still expand:
include
is a function in Helm which "will import the contents of a template into the present pipeline where it can be passed along to other functions in the pipeline" (from the Helm documentation here)
In my example, $template
is a variable containing the name of a named template, exactly the same as your first example. I had thought that your original example could have been rewritten like this:
{{ define "first" }} First {{ end }}
{{ $template := "first" }}
{{ template (printf "%s" $template) . }}
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.
from sprig.
Related Issues (20)
- sprig still alive? HOT 1
- support pipe for `omit` and `pick`
- Expose digFromDict function HOT 1
- (feat): Implement PBKDF2 as cryptographic function
- Time Comparison Functions HOT 4
- Parse Seconds from Duration HOT 2
- Map function
- How can I avoid getting a scientific notation in a large multiply? HOT 1
- How to convert "a b c" string to json ["a","b","c"]? HOT 1
- required function
- dateInZone silently fails when it doesn't understand the parameters passed to it
- Proposal: add toDuration HOT 2
- apostrophes are transformed by printf function HOT 1
- Typo in release 2.10.0 Changelog.
- Derive password documentation broken
- Merging a dict over other types fails silently
- is this still supported? HOT 6
- Change return types of "split" and "splitn" to map[string]interface{} (instead of map[string]string)
- filter complex list
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sprig.