add option 'snippet returns false' to rendering options menu

  • 1
  • Idea
  • Updated 2 years ago
When picking an option to render something it would be convenient to have an option "snippet returns false" in addition to the option of  "snippet returns true."


My use case:

I have two buttons. One says "show preferred records only", which queries a model to show user specific preferred records, and another that says "show all records" which queries a model and ignores the model condition for user preferred records. I only want to show one button at a time. When the preferred records are displayed, I show "show all records" and when all records are displayed, I show the button "show preferred records only." In order to do that, I had to write two snippets, which do the same exact thing, except one returns the complement value of the other.

If I had an option of "snippet returns false" I'd be able to get away with one snippet!
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb

Posted 2 years ago

  • 1
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Shmuel,

Can you just have your snippet check the value of whatever field you're using to conditionally render your buttons to decide if it should include the condition or not?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Ah, nevermind...

But I think in your use case you could just create a ui-only checkbox to turn on/off and use that for your rendering condition. That would allow you to have one snippet, if I'm understanding correctly.
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb
That's what I ended up doing, thanks! I try to keep the number of components/fields small since it's not possible to document it in the page (and I can document JavaScript).