Depending on the return type of $page->typeface()
method, and the placement of the code (looks like you're on a template view), I might opt for:
<?php if ($typeface === $page->typeface()): ?>
<li><span>Typeface: </span><?=$typeface?></li>
<?php endif; ?>
PHP docs here:
Alternative syntax for control structures
See here for cautions you should consider when using <?=...?>
short tags.
An alternative to <?=...?>
would be: <?php echo $typeface; ?>
.
Hope that helps!
EDIT:
Actually, I second-guessed myself earlier (I blame sleep deprivation). I originally had this code (except for the trim()
):
<?php if ($typeface = trim($page->typeface())): ?>
<li><span>Typeface: </span><?=$typeface?></li>
<?php endif; ?>
Where I'm setting the variable $typeface
in the if()
. This technique should shorten your code by a line.
Here's a working example using simple strings:
<?php $foo = ""; ?>
...
<?php if ($typeface = trim($foo)): ?>
<li><span>Typeface: </span><?=$typeface?></li>
<?php endif; ?>
... outputs: Nothing.
<?php $foo = 'I\'m a string!'; ?>
...
<?php if ($typeface = trim($foo)): ?>
<li><span>Typeface: </span><?=$typeface?></li>
<?php endif; ?>
... outputs: <li><span>Typeface: </span>I'm a string!</li>
(obviously, missing the opening and closing <ul></ul>
.