Liquid If/Else problem


10 Comentarios

  • 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!

  • Oliver Knigge

    Hi Jessie,

    thank you very much.

    "The available Boolean operators are:

    • and
    • or"


    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 == 'Group A' or == 'Group B' or == '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' %}
    {% else %}
    {% 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 :)

  • 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 %}
    {% 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. 


  • 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 %}
    {% 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:

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

  • 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!

  • 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:

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

  • Oliver Knigge

    Problem solved within this thread:

    Finally! :)

  • Nicole S.
    Zendesk Community Team

    Hey Oliver, 

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

  • 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'}

  • 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.



Iniciar sesión para dejar un comentario.

Tecnología de Zendesk