Kentico IF else if else statement

Dominic Carvalho asked on August 12, 2018 11:32

Hey, I am struggling to get a simple else if statement to work, What is the correct structure for the statement ? It works with a normal if else statement but when I try add another if in it, it breaks. I am currently trying it like this:

{% if(menuName == "{$copyright$}") { %}

  • <a href="/terms-conditions#copyright" {%gtmIdFooter%}>{%menuName%}
  • {% } else if(menuName == "{$affiliates$}") { %}
  • <a href="different like" {%gtmIdFooter%}>{%menuName%}
  • {% } else { %}
  • <a href="{% GetDocumentUrl %}" {%gtmIdFooter%}>{%menuName%}
  • {% } %}

    Any help will be greatly appreciated :)

    Correct Answer

    Peter Mogilnitski answered on August 12, 2018 14:53

    You have anchors not closed and assuming your gtmIdFooter and menuName are defined somewhere, it should be:

    {% 
    result = "<a href='" + GetDocumentUrl() + "' " + gtmIdFooter + ">" + menuName + "</a>"
    
    if(menuName == GetResourceString("copyright")) { result = "<a href='/terms-conditions#copyright' " + gtmIdFooter+ ">" + menuName + "</a>" }
    if(menuName == GetResourceString("affiliates")) { result = "<a href='different like' " + gtmIdFooter+ ">" + menuName + "</a>" }
    
    return result;
    |(identity)GlobalAdministrator%}
    
    0 votesVote for this answer Unmark Correct answer

       Please, sign in to be able to submit a new answer.