Developer User Group - September Meetup: Liquid

1 コメント

  • Ahmed Zaid
    User Group Leader Community Moderator

    Thanks to Stephen Belleau for sharing a great tip on one of his use cases:

    A fun use case for liquid, we sometimes want to render something if a certain tag is present on a ticket. For example, each ticket will always have a tag that defines SLA and it is always formatted as "bronze_sla" or "silver_sla". So I iterate through the tags and check the last four characters for a match: (whitespaces added for code readability)

    {% assign array = ticket.tags | split: " " %}
    {%- for tag in array -%}
    {%- assign suffix = tag | slice: -4,4 -%}
    {%- if suffix == "_sla" -%}
    {%- if tag contains "bronze" -%}
    Bronze
    {%- elsif tag contains "silver" -%}
    Silver
    {%- elsif tag contains "gold" -%}
    Gold
    {%- elsif tag contains platinum -%}
    Platinum
    {%- endif -%}
    {%- endif -%}
    {%- endfor %}
    0

サインインしてコメントを残してください。

Powered by Zendesk