Support for one liner conditional statement using ternary operator. #721
Unanswered
sanketdhoble
asked this question in
Q&A
Replies: 2 comments
-
Unfortunately no. But I agree this would be a good feature, given all the discussions I see here: Shopify/liquid#236 While the implementation would be changing the fundamental syntax, expect this feature won't come anytime soon. I'll leave this issue open for people to track. |
Beta Was this translation helpful? Give feedback.
0 replies
-
@sanketdhoble Not sure if it helps, but I've generally used a custom filter similar to this in the past: import { Liquid } from "liquidjs";
const engine = new Liquid();
engine.registerFilter("ternary", (value, truthyValue, falsyValue) =>
!!value ? truthyValue : falsyValue
);
engine
.parseAndRender('{{ data.age < 18 | ternary: "You are under 18", "You are over 18" }}', { data: { age: 8 } })
.then(console.log); // outputs 'You are under 18' |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Does liquid js support one-liner conditional msg using ternary operator?
e.g: I want to do something like this but it doesn't work.
Beta Was this translation helpful? Give feedback.
All reactions