Comments (7)
Found a solution {{ kindIs "invalid" $value }}
from sprig.
Wow. That issue actually helped me nail down an issue I was seeing in a local PVC! Ha!
Okay, so an {{ if $value }}
will check for both ""
and nil
, considering either one to be an "empty value". There is also the empty
function, which essentially behaves the same way.
It might be nice to be able to test whether something is nil
and possibly empty ({{ if isNil $foo }}
). I don't think we have a way of checking that. Maybe eq $foo nil
would work... I've never tried.
Does that answer your question, or am I misunderstanding.
from sprig.
@scottrigby @technosophos Here's an example of the previous comment... https://play.golang.org/p/9yJW5iGT4qa
When I looked at this in the past I'd not thought of this. Thanks @jkroepke
from sprig.
OK, I found the relevant helm issue: helm/helm#2600
But just checking here, is there really no way for sprig to differentiate the difference between nil
and ""
(empty string) in a template? If not, would that be a desirable PR?
from sprig.
@technosophos If something is a string, isn't the initialized value on a struct ""
instead of nil
? How would you get the nil
state without the template engine complaining about the missing field?
I imagine I'm missing something which is why I ask.
from sprig.
Love it 😄
from sprig.
Found a solution
{{ kindIs "invalid" $value }}
@jkroepke While this solution might work, I imagine there are other cases where the "kind" of something might be "invalid" without it being nil
.
I think better option is to use a direct equality check against nil
:
{{ eq $value nil }}
PS: the reason that the kind of nil
equals "invalid" is actually because nil
does not have a type in Go, because it is a "predeclared identifier".
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
- Feature Request: add "yield" function HOT 5
- 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.