Developer forum

Forum » CMS - Standard features » Else if in 'HTML'

Else if in 'HTML'

Marc Hjorth
Marc Hjorth
Reply

Hey

I was wondering if you are able to make an If, else If, else statement in a HTML template.

So far I found this documentation -  but I can't seem to find or get a statement of that kind to work.

 - https://doc.dynamicweb.com/template-tags/introduction/conditionals/if-statements
 - https://doc.dynamicweb.com/Files/Images/_TagReference/General/IF_Statements.txt

 

Seems like a standard if, else statement like below is the only option, or am I wrong?

<!--@If[ Not](Templatetag[=|<>|>|<|<=|>=|<contains>|<startswith>|<endswith>]testvalue)-->
    text to print if condition is met
<!--@Else-->
   text to print 
<!--@EndIf-->

 

Best regards,

Marc Hjorth


Replies

 
Nicolai Pedersen
Reply

Hi Marc

Not sure I understand what you want - like this? I think you can. But I would advice to convert to cshtml if you need more advanced conditional options in your templates.

<!--@If[ Not](Templatetag[=|<>|>|<|<=|>=|<contains>|<startswith>|<endswith>]testvalue)-->
    <!--@If[ Not](Templatetag[=|<>|>|<|<=|>=|<contains>|<startswith>|<endswith>]testvalue)-->
        text to print if condition is met
    <!--@Else-->
       text to print 
    <!--@EndIf-->

<!--@Else-->
   text to print 
<!--@EndIf-->

BR Nicolai

 
Marc Hjorth
Marc Hjorth
Reply

Thank you for the quick reply

It works alright, but I would like to optimize it a bit.

I got a text field and a checkbox, and 4 possible scenarios.

  • If the text field is 'Defined' (contains text), it has to be displayed.
  • If the checkbox is 'Defined' (checked), it has to display another text which is static
  • If both the text field and checkbox is 'Defined', it has to display the text field text.
  • If none of the fields are 'Defined', nothing should be displayed.

Is it possible to handle this with this 'HTML-logic' ?

 
Nicolai Pedersen
Reply
This post has been marked as an answer

I woudl convert to razor...

But I think you can build it like this:

If text field is defined
--> display text
else
If checbox defined
--> display checbox
else
--> display nothing
end
end
Votes for this answer: 1
 
Marc Hjorth
Marc Hjorth
Reply

Converting to razor seems to be the optimal solution in this case, thanks anyway :) 

 

You must be logged in to post in the forum