Giter VIP home page Giter VIP logo

Comments (7)

jkroepke avatar jkroepke commented on May 21, 2024 83

Found a solution {{ kindIs "invalid" $value }}

from sprig.

technosophos avatar technosophos commented on May 21, 2024 8

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.

mattfarina avatar mattfarina commented on May 21, 2024 1

@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.

scottrigby avatar scottrigby commented on May 21, 2024

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.

mattfarina avatar mattfarina commented on May 21, 2024

@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.

scottrigby avatar scottrigby commented on May 21, 2024

Love it 😄

from sprig.

thesuperzapper avatar thesuperzapper commented on May 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.