Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom variable #1023

Closed
MiladRahmani opened this issue Sep 6, 2018 · 4 comments
Closed

custom variable #1023

MiladRahmani opened this issue Sep 6, 2018 · 4 comments

Comments

@MiladRahmani
Copy link

MiladRahmani commented Sep 6, 2018

Is it possible to create custom variable in liquid ?
E.g in {{ x | A | B }} do that if x > 10 show "A" else show "B" and "A" , "B" can change by user
Thank you

@callaginn
Copy link

Yes, use "assign" or "capture" to create a custom variable:
https://help.shopify.com/en/themes/liquid/tags/variable-tags#assign
https://help.shopify.com/en/themes/liquid/tags/variable-tags#capture

You can add conditional statements with "if", "unless", or "case" tags:
https://help.shopify.com/en/themes/liquid/tags/control-flow-tags#if

@MiladRahmani
Copy link
Author

Yes that's right but i want to use if else statment in one line, that mean that if 'x' was true show 'A' else show 'B'
Can you help me, please?

@callaginn
Copy link

Like this?

{% assign x = '12' %}
{% if x > 10 %}{{ a }}{% else %}{{ b }}{% endif %}

@shopmike
Copy link
Contributor

shopmike commented Oct 2, 2019

@callaginn has provided the cleanest option thats currently possible. I think you may also be referring to a ternary operator, sadly Liquid does not have this functionality.

@shopmike shopmike closed this as completed Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants