if statement not working in html envelope

Alan Isaacson asked on November 22, 2016 15:30

Hi, I am trying to add the following code into an html envelope. <nav aria-label="{% CurrentDocument.DocumentName #%}menu" class="vs-menu-secondary {% CurrentDocument.DocumentName#%}"> {% if (CurrentDocument.DocumentName.ToString() == "Learn" ){ "<img src='/Vetstream/media/images/Site%20assets/logo-vetacademy.png' alt='Learn with Vetacademy' class='is-responsive' />"}#%}
{% else if (CurrentDocument.DocumentName.ToString() == "Treat" ){ "<img src='/Vetstream/media/images/Site%20assets/logo-vetlexicon.png' alt='Treat with Vetlexicon' class='is-responsive' />"}#%}
However the first if statement for the learn DocumentName works but the treat one doesn't. It doesn't matter what order I put the if statements. If I write out either the document name or image path outside of the if statement they appear correctly.

Such as {% CurrentDocument.DocumentName %} and <img src='/Vetstream/media/images/Site%20assets/logo-vetlexicon.png' alt='Treat with Vetlexicon' class='is-responsive' />

Any help appreciated as always

Correct Answer

Trevor Fayas answered on November 22, 2016 15:35

With K#, you often need to be careful putting linked macros across multiple lines, and follow the format in the K# Macro syntax:

{% date = CurrentDateTime; if (date.Year > 2013) { %}
The current date is: {% date %}. The registration period has ended.
{% } %}

In your case, it would look like this:

{% if (CurrentDocument.DocumentName.ToString() == "Learn" ){ %}
<img src='/Vetstream/media/images/Site%20assets/logo-vetacademy.png' alt='Learn with Vetacademy' class='is-responsive' />
{% } else if (CurrentDocument.DocumentName.ToString() == "Treat" ){ %}
 <img src='/Vetstream/media/images/Site%20assets/logo-vetacademy.png' alt='Learn with Vetacademy' class='is-responsive' />
 {% } %}

Or, you could just do 2 if statements, since you don't really need an "if else" here.

{% if (CurrentDocument.DocumentName.ToString() == "Learn" ){ "<img src='/Vetstream/media/images/Site%20assets/logo-vetacademy.png' alt='Learn with Vetacademy' class='is-responsive' />"}#%}

{% if (CurrentDocument.DocumentName.ToString() == "Treat" ){ "<img src='/Vetstream/media/images/Site%20assets/logo-vetlexicon.png' alt='Treat with Vetlexicon' class='is-responsive' />"}#%} 
0 votesVote for this answer Unmark Correct answer

Recent Answers


Alan Isaacson answered on November 22, 2016 15:55

How odd, I tried it two statements before and still the 2nd one failed. I have just copied and pasted your version and it now works. Can't see a difference to what I tried before adding the else, just another oddity of life. Many thanks

0 votesVote for this answer Mark as a Correct answer

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