What is the correct way of embedding if else and elseif conditions inside html?
See Question&Answers more detail:osWhat is the correct way of embedding if else and elseif conditions inside html?
See Question&Answers more detail:osI recommend the following syntax for readability.
<? if ($condition): ?>
<p>Content</p>
<? elseif ($other_condition): ?>
<p>Other Content</p>
<? else: ?>
<p>Default Content</p>
<? endif; ?>
Note, omitting php
on the open tags does require that short_open_tags
is enabled in your configuration, which is the default. The relevant curly-brace-free conditional syntax is always enabled and can be used regardless of this directive.