Liquid If/Else problem

10 Kommentare

  • Jessie Schutz
    Zendesk team member

    Hi Oliver!

    I am by no means a Liquid expert, but I'm wondering if the 'Group A' or 'Group B' condition might be the problem. Is an OR condition generally supported in Liquid? 

    We have a couple Community Moderators who are good with Liquid so I'm going to track them down and ask them to weigh in on this! Sit tight!

    0
  • Oliver Knigge

    Hi Jessie,

    thank you very much.

    "The available Boolean operators are:

    • and
    • or"

    (source: https://github.com/Shopify/liquid/wiki/Liquid-for-Designers)

    It is really confusing. I have if-expressions in multiple triggers, sometimes they work correctly, sometimes the expression is always true (even if it should be false). 

    And I have tried so many versions like

    {% if ticket.group.name == 'Group A' or ticket.group.name == 'Group B' or ticket.group.name == 'Group C' %}

    This also doesn't work. Don't know what is happening exactly.

    I have solved the problem for now with creating more triggers. I have the conditions, which are not working with Liquid in the trigger now. 

    But I see the next problem is occuring...

    If-expressions with the "ticket.tags" attribute seems to be also not working.
    The following example won't work:

    {% for comment in ticket.comments %}
    {% if ticket.tags contains 'tag_1' or 'tag_2' and forloop.last == 'true' %}
    End
    {% else %}
    {{comment.value}}
    {% endif %}
    {% endfor %}

    With this expressions, I would like to have a comment history in the e-mail notification. 
    When having specific tags in the ticket, I do not want to show the earliest (first) comment (=submit) in the ticket history, only the word "End".

    As explained above, the if-expression with the ticket.tag attribute is always true and I'm getting always "End", even the ticket does not have such tags or it is not the last forloop.

    I have also tried

    {% assign tags = ticket.tags | split: " " %}

    and then using the tags-variable in the if-expression - same result, always true.

    This is strange :)

    1
  • Oliver Knigge

    Now I have tried it with nested if-expression - again not working :(

    {% for comment in ticket.comments offset:1 %}
    {% if forloop.last == true %}{% if ticket.tags contains 'tag_1' or 'tag_2' %}{% break %}{% endif %}{% endif %}
    {{comment.value}}
    {% endfor %}

    But here the output is always the {{comment.value}} even it is the last loop and the ticket.tags contains 'tag_1' or 'tag_2' - But here it should completely end the forloop ("break") - it does not work :(

    I absolutely don't know how this is happening. 

     

    0
  • Oliver Knigge

    Just to be up to date:

    Now I have found out, that the if-expression with the "forloop.last" attribute is working.

    {% for comment in ticket.comments offset:1 %}
    {% if forloop.last == true %}{% break %}{% endif %}
    {{comment.value}}
    {% endfor %}

    This puts me out the comment history without the first ticket comment/submitting description (last forloop). 

    So I need a solution for the ticket.tags. I have found a workaround here:

    https://support.zendesk.com/hc/en-us/community/posts/203413686-Using-zendesk-tags-in-liquid-markup

    But I do not understand the liquid {% capture %} tag exactly. Can anyone help?

    1
  • Jessie Schutz
    Zendesk team member

    Hey Oliver!

    I haven't had a chance to actually learn Liquid yet, so I'm afraid I can't be of any help. But I have brought this to the attention of our awesome Community Moderators, so hopefully they'll be able to give you some insight!

    0
  • Oliver Knigge

    Hi, thanks again! :)

    And no problem, I have posted a lot and I can totally understand, that you do not have a tip on each comment :)
    Liquid is a really complex language.

    I just want you or the moderators to be up to date with what I'm doing.That's why I'm posting every step I've tried.

    Maybe I get some help over here too:
    https://support.zendesk.com/hc/en-us/articles/203662146?page=2#comment_115001689508

    I am in cheerful spirits that we get this solved :)
    For now, I wish you a pleasent and sunny weekend!

    0
  • Oliver Knigge

    Problem solved within this thread:

    https://support.zendesk.com/hc/en-us/articles/203662146?page=2#comment_115001701668

    Finally! :)

    1
  • Nicole S. - Community Manager
    Zendesk Community Team

    Hey Oliver, 

    Glad to hear you got an answer to your question - thanks for updating the thread!

    0
  • Donald Cornel

    Hi There!

    I don't know if this is the right topic for me to write my concern.

    I'm trying to make a trigger that will notify specific email user for every update of a ticket.

    I just can't find a proper placeholder for my condition.

    here's the logic:

    if a ticket update has a comment either public or internal

    then {{ticket.comments_formatted}}

    else {'predefined text'}

    0
  • Chris Bulin
    Community Moderator

    Hi Donald Cornel I can't find a placeholder that would do what I think you are wanting to do. You can use liquid markup to create dynamic content, but that content has to be based on something in Zendesk (like business hours or a ticket field) rather than a freestanding text block I believe. There's are quite a few examples linked in the Liquid Markup article.

     

    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.

Powered by Zendesk