I need some help with the below alternative if-else syntax. I use this very frequently and it works with a 99.999999% success rate. Here, for some reason, it doesn't:
if ( get_row_layout() == 'spacer' ) :
$spaceheight = get_sub_field('spacer_height');
// The Alternative Syntax: if... else statement without a colon
// Once these two lines are removed OR changed into "if ( some
// condition ) : some stuff; endif;" syntax >> the error goes
// away.
if ( $spaceheight && ( 0 !== $spaceheight ) )
echo "<div class='basf-spacer' style='display: block; width: 100%; height: {$spaceheight}px; background: transparent; padding: 0; margin: 0; font-size: 0; line-height: 0;'></div>";
elseif ( get_row_layout() == 'terms' ) :
// Some other stuff
endif;
The specific error message is: "Parse error: syntax error, unexpected ':' in... "; and the colon is unexpected after the alternative syntax, in the elseif ( get_row_layout() == 'terms' ) :
line.
Any idea what's happening here?
@antoni suggested the answer is that alternative syntaxes can't be mixed. But in this case why does this work?:
if ( $terms_primcont || $terms_seccont ) : ?>
<div class="terms__body-wrap">
<?php
if ( $terms_primcont ) echo "<div class='terms__primary'>{$terms_primcont}</div>";
if ( $terms_seccont ) echo "<div class='terms__secondary'>{$terms_seccont}</div>";
?>
</div>
<?php endif;